记住这个代码:
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')
);
Run Code Online (Sandbox Code Playgroud)
是不是国家应该在3秒后改变?它正在迅速改变.
我的主要目标是每隔3秒(有setInterval())改变状态,但由于它不起作用,我试过setTimeout(),这也没有用.这有什么灯吗?谢谢!