How to dispatch a Redux action with a timeout?

后端 未结 12 1934
花落未央
花落未央 2020-11-22 04:14

I have an action that updates the notification state of my application. Usually, this notification will be an error or info of some sort. I need to then dispatch another act

12条回答
  •  心在旅途
    2020-11-22 04:47

    It is simple. Use trim-redux package and write like this in componentDidMount or other place and kill it in componentWillUnmount.

    componentDidMount() {
      this.tm = setTimeout(function() {
        setStore({ age: 20 });
      }, 3000);
    }
    
    componentWillUnmount() {
      clearTimeout(this.tm);
    }
    

提交回复
热议问题