Why does calling react setState method not mutate the state immediately?
I'm reading Forms section of reactjs documentation and just tried this code to demonstrate usage (JSBIN).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')
);
When I update the value in the browser, the second inside the callback prints the same as the first , Why I can't see the result of in the scope of callback?<input/>
console.log
handleChange
value
console.log
this.setState({value: event.target.value})
handleChange