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