I'm reading Forms section of reactjs documentation and just tried this code to demonstrate onChange
usage ( JSBIN ).
(我正在阅读reactjs文档的Forms部分,只是尝试了这段代码来演示onChange
用法( 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?
(当我在浏览器中更新<input/>
值时, handleChange
回调内的第二个console.log
与第一个console.log
打印相同的value
,为什么我看不到this.setState({value: event.target.value})
在handleChange
回调的范围内?)
ask by tarrsalah translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…