-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Description
http://facebook.github.io/react/tips/props-in-getInitialState-as-anti-pattern.html
A component should not sync its state with its props, the 2 must be separate, like in any form input element in React, i.e an input element created using: <input value={apple} type={text}/>
will always have the value 'apple' no matter what the user does.
The only way to change the value of the input component is by updating its props. <input value={this.state.x} type={text} onChange={this.handleChange} />
However this is not true in the case of react-select, as it syncs its state with props and the state can also be changed by user-input (multiple sources of truth).
The render method must use values from props instead of state. State maybe used to support access to value in the handleChange event, analogous to (this.refs.myInputElement.getDOMNode().value)