No .bind() or Arrow Function in JSX Props

来源:互联网 发布:dmp数据 编辑:程序博客网 时间:2024/04/29 22:45

No .bind() or Arrow Function in JSX Props

issue from

https://github.com/MichaelCereda/react-native-form-generator/issues/45

warning code

export class InputField extends React.Component{  handleValidation(isValid, validationErrors){    this.valid = isValid;    this.validationErrors = validationErrors;  }  setValue(value){    this.refs.fieldComponent.setValue(value)  }  focus(){    this.refs.fieldComponent.focus()  }  render(){    return(<InputComponent      {...this.props}      ref='fieldComponent'      onValidation={this.handleValidation.bind(this)}      //onChange={this.handleChange.bind(this)}      //ref={this.props.fieldRef}      />    );  }}

optimize code

export class InputField extends React.Component{  handleValidation(isValid, validationErrors){    this.valid = isValid;    this.validationErrors = validationErrors;  }  setValue(value){    this.refs.fieldComponent.setValue(value)  }  focus(){    this.refs.fieldComponent.focus()  }  render(){    return(<InputComponent      {...this.props}      ref='fieldComponent'      onValidation={this.handleValidation}      />    );  }}
  • readOne
  • readTwo
0 0
原创粉丝点击