First, the pillars are what has been conveyed to you. View them as function parameters. The child really should not change them, because it violates all the assumptions that the parent has and makes your user interface inconsistent.
Here, since prop passed you, you want to get a handler from the parent, which you can call to notify about this:
var App = React.createClass({ getInitialState: function() { return {inputValue: ''}; }, handleChange: function(value) { console.log('Value gotten back from the child: ' + value); this.setState({ inputValue: value }); }, render: function() { return <Field onChange={this.handleChange} inputValue={this.state.inputValue} />; } }); var Field = React.createClass({ handleChange: function(event) {
So yes, it is updated "automatically" if you tell your parents to change. Instead of changing what was passed to you, you use vanilla callbacks to your parents, passing it a new value. Then it resets the same value (or another, if appropriate) to you.
chenglou
source share