记住以下代码:
var Component = React.createClass({
getInitialState: function () {
return {position: 0};
},
componentDidMount: function () {
setTimeout(this.setState({position: 1}), 3000);
},
render: function () {
return (
<div className="component">
{this.state.position}
</div>
);
}
});
ReactDOM.render(
<Component />,
document.getElementById('main')
);
难道状态不应该在3秒钟后改变吗?它马上就变了.
我在这里的主要目标是每3秒改变一次状态(setInterval()
),但由于它不起作用,我try 了setTimeout()
,它也不起作用.这上面有灯吗?谢谢