formsy-react-components icon indicating copy to clipboard operation
formsy-react-components copied to clipboard

onChange is called before the value has been set on formsy

Open ewingrj opened this issue 6 years ago • 0 comments

This leads to problems where the previous value is flashed after a change if I call setState in my onChange function. This happens because the component is re-rendered, and formsy passes the value before change to the Input, leading the input to update it state w/ the previous value. Then the formsy setValue finishes, and the input updates its state again using the updated value.

handleOnChange(name, value) {
  this.setState({pending: true})
  ... some async check
  this.setState({pending: false, result})
}

render() {
  <Input name='name' onChange={this.handleOnChange.bind(this)}/>
}

ewingrj avatar Apr 16 '19 14:04 ewingrj