Answer by Mohmmad Ebrahimi Aval for How to dispatch a Redux action with a...
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:...
View ArticleAnswer by Vanuan for How to dispatch a Redux action with a timeout?
Why should it be so hard? It's just UI logic. Use a dedicated action to set notification data: dispatch({ notificationData: { message: 'message', expire: +new Date() + 5*1000 } }) and a dedicated...
View ArticleAnswer by Bloomca for How to dispatch a Redux action with a timeout?
Redux itself is a pretty verbose library, and for such stuff you would have to use something like Redux-thunk, which will give a dispatch function, so you will be able to dispatch closing of the...
View ArticleAnswer by cnexans for How to dispatch a Redux action with a timeout?
I understand that this question is a bit old but I'm going to introduce another solution using redux-observable aka. Epic. Quoting the official documentation: What is redux-observable? RxJS 5-based...
View ArticleAnswer by Alireza for How to dispatch a Redux action with a timeout?
The appropriate way to do this is using Redux Thunk which is a popular middleware for Redux, as per Redux Thunk documentation: "Redux Thunk middleware allows you to write action creators that return a...
View ArticleAnswer by Tyler Long for How to dispatch a Redux action with a timeout?
A repository with sample projects Current there are four sample projects: Writing Async Code Inline Extracting Async Action Creator Use Redux Thunk Use Redux Saga The accepted answer is awesome. But...
View ArticleAnswer by Yash for How to dispatch a Redux action with a timeout?
If you want timeout handling on selective actions, you can try the middleware approach. I faced a similar problem for handling promise based actions selectively and this solution was more flexible....
View ArticleAnswer by Jeff Barczewski for How to dispatch a Redux action with a timeout?
After trying the various popular approaches (action creators, thunks, sagas, epics, effects, custom middleware), I still felt that maybe there was room for improvement so I documented my journey in...
View ArticleAnswer by Sebastien Lorber for How to dispatch a Redux action with a timeout?
Using Redux-saga As Dan Abramov said, if you want more advanced control over your async code, you might take a look at redux-saga. This answer is a simple example, if you want better explanations on...
View ArticleAnswer by Jean-Jacques Dubray for How to dispatch a Redux action with a timeout?
I would recommend also taking a look at the SAM pattern. The SAM pattern advocates for including a "next-action-predicate" where (automatic) actions such as "notifications disappear automatically after...
View ArticleAnswer by Dan Abramov for How to dispatch a Redux action with a timeout?
Don’t fall into the trap of thinking a library should prescribe how to do everything. If you want to do something with a timeout in JavaScript, you need to use setTimeout. There is no reason why Redux...
View ArticleAnswer by Fatih Erikli for How to dispatch a Redux action with a timeout?
You can do this with redux-thunk. There is a guide in redux document for async actions like setTimeout.
View ArticleHow to dispatch a Redux action with a timeout?
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...
View ArticleAnswer by Irfanullah Jan for How to dispatch a Redux action with a timeout?
This may be a bit off-topic but I want to share it here because I simply wanted to remove Alerts from state after a given timeout i.e. auto hiding alerts/notifications.I ended up using setTimeout()...
View ArticleAnswer by Audrey for How to dispatch a Redux action with a timeout?
Redux actions can just return a plain object, not functions, callbacks, or asynchronous processes. For dispatching them through web API such as timeout() method you have to use redux-thunk middleware....
View Article