If you don't use an initial model for a form, React with display this error message once the onChange
event is triggered for the first time:
Warning: OtherForm is changing an uncontrolled input of type text to be controlled. Input elements should not switch from uncontrolled to controlled (or vice versa). Decide between using a controlled or uncontrolled input element for the lifetime of the component. More info: https://fb.me/react-controlled-components
This warning is easily avoided by just using an initial model or by doing something like value={model.firstName || ''}
. But perhaps bindInput
could be updated to do this by default, something like this:
bindInput = (name) => {
return {
name,
value: this.state.model[name] || '',
onChange: this.bindToChangeEvent,
}
}
Happy to open a PR if you think this is good idea.