在更改状态之前使用setTimeout和React.js

时间:2016-03-02 22:03:26

标签: reactjs

我想在更改函数中的状态之前使用setTimeout和React.js。我想在onHeaderTyped函数中使用它。我尝试过包含TimerMixin,但收到了一个错误(未定义)。还有其他路线吗?

Typing = React.createClass({

  getInitialState: function() {
      return { showFirst: true, showSecond: false, showThird: false };
  },

  onHeaderTyped: function() {
      this.setState({showFirst: false});
      this.setState({showSecond: true});
  },

  onSecondTyped: function() {
      this.setState({showSecond: false});
      this.setState({showThird: true});

  },

  onThirdTyped: function() {
    this.setState({showThird: false});
    this.setState({showFirst: true});

  },

  render: function() {
    const docs = '#one';
    return (



<div>
      <div className="TypistExample">

        {this.state.showFirst ? (

        <Typist className="TypistExample-header" avgTypingSpeed={100} startDelay={1000}
          onTypingDone={this.onHeaderTyped} cursor={{hideWhenDone: true}}>
          <h1><a href={docs}>First Stuff</a></h1>
        </Typist>

        ) : null }

        {this.state.showSecond ? (

        <Typist className="TypistExample-header" avgTypingSpeed={100} startDelay={1000} 
          onTypingDone={this.onSecondTyped}>
          <h1> Some Stuff </h1>
        </Typist>

        ) : null }

        {this.state.showThird ? (

        <Typist className="TypistExample-header" avgTypingSpeed={100} startDelay={1000} 
          onTypingDone={this.onThirdTyped}>
          <h1> More Stuff </h1>
        </Typist>

        ) : null }


      </div>
</div>

    );
  }

});

顺便说一下,在运行时,我收到了这个错误:

警告:setState(...):只能更新已安装或安装的组件。这通常意味着您在已卸载的组件上调用了setState()。这是一个无操作。请检查未定义组件的代码。

0 个答案:

没有答案