twisty / formsy-react-components

Bootstrap components for a formsy-react form.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

onChange is called before the value has been set on formsy

ewingrj opened this issue · 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)}/>
}