React Native - text input blinking when using state

后端 未结 2 1157
无人及你
无人及你 2021-01-21 21:19

I\'m adding some validation to the input text of a TextInput component. The TextInput\'s value is handled in the state and is only updated when the value entered is valid.

2条回答
  •  隐瞒了意图╮
    2021-01-21 21:35

    you can try to use '=>' operator

    class TextInputWithValidation extends Component {
    
    constructor(props) {
      super(props);
      this.state = { text: ''}
      this.handleChange = this.handleChange.bind(this);
    }
    //here
    handleChange = (text) => {
      if(isValid) {
          this.setState({text})
      }
    }
    
    render() {
      return (
               this.handleChange}
              />
      )
    }
    }
    

提交回复
热议问题