如何在React中更改计时器组件中不相关组件的状态

时间:2016-08-09 13:45:02

标签: reactjs timer components state

我有一个Timer组件,只需点击一下按钮即可启动:

handleClick: function() {
        if (this.state.running == 0) {
          this.setState({running: 1});
          ReactDOM.render(<Timer start={Date.now()} round={0} />,document.getElementById('timer'));
        }
      },
      render: function() {
         return  (
              <button onClick={this.handleClick}>Začni simulacijo</button>  
         );
      } 

这会启动Timer,它有一个tick函数,用于检查是否需要更新值表(也是React组件)......这种情况发生在这里:

tick: function(){

          round = Math.floor(this.state.elapsed / seasonParams.gameDayTime);
          if (round > this.state.round) {
            var result = config.pairs.filter(function( obj ) {
              return obj.round == round;
            });
            this.setState({elapsed: new Date() this.props.start,"round":round }); //this sets state of timer component

            //HERE I WOULD NEED TO ADD SET STATE OF THE TABLE COMPONENT
          } 

          console.log("elapsed: "+this.state.elapsed+", round: "+round);
      },

Table组件接受一个对象数组来呈现表...但与Timer或Button组件无关。如何在Timer中将新发现的数据传递给它?

谢谢...

0 个答案:

没有答案