How to dispatch a Redux action with a timeout?

2018-12-31 08:28发布

I have an action that updates notification state of my application. Usually, this notification will be an error or info of some sort. I need to then dispatch another action after 5 seconds that will return the notification state to initial one, so no notification. The main reason behind this is to provide functionality where notifications disappear automatically after 5 seconds.

I had no luck with using setTimeout and returning another action and can't find how this is done online. So any advice is welcome.

13条回答
与君花间醉酒
2楼-- · 2018-12-31 09:02

You can do this with redux-thunk. There is a guide in redux document for async actions like setTimeout.

查看更多
登录 后发表回答