ReactJS: setTimeout() not working?

前端 未结 10 2177

Having this code in mind:

var Component = React.createClass({

    getInitialState: function () {
        return {position: 0};    
    },

    componentDid         


        
10条回答
  •  时光取名叫无心
    2020-12-04 08:05

    setState is being invoked immediately due to the parenthesis! Wrap it in an anonymous function, then call it:

    setTimeout(function() {
        this.setState({position: 1})
    }.bind(this), 3000);
    

提交回复
热议问题