为什么调用ReactisesetState方法不立即改变状态?
onChange
var React= require('react');var ControlledForm= React.createClass({ getInitialState: function() { return { value: "initial value" }; }, handleChange: function(event) { console.log(this.state.value); this.setState({value: event.target.value}); console.log(this.state.value); }, render: function() { return ( <input type="text" value={this.state.value} onChange={this.handleChange}/> ); }});React.render( <ControlledForm/>, document.getElementById('mount'));
<input/>
console.log
handleChange
value
console.log
this.setState({value: event.target.value})
handleChange
FFIVE
DIEA
相关分类