我有在它超过10个字段一个反应基形式,我的状态对那些10个form字段(控制部件).
这些input字段中的大多数text仅为类型,但稍后将添加其他类型字段.
问题是我需要为它们编写10个更改处理程序以正确设置状态,然后在构造函数中为每个处理程序添加方法绑定.
我很反应,可能不了解正确的方法和技术.
请指导我如何改进我当前的代码结构,避免编写样板和重复的错误代码.
我目前的注册组件如下 -
export default class Register extends Component {
constructor(props){
super(props);
this.state = {
regName : '',
regAdd1 : '',
regAdd2 : '',
regState : '',
regZipCode : '',
regCity : '',
regPhone : ''
};
// add bindings .... ugh..
this.changeRegAdd1 = this.changeRegAdd1.bind(this);
this.changeRegAdd2 = this.changeRegAdd2.bind(this);
//Similary binding for other handlers...
}
// add individual field change handlers …Run Code Online (Sandbox Code Playgroud)