Quantcast
Channel: How to dispatch a Redux action with a timeout? - Stack Overflow
Viewing all articles
Browse latest Browse all 15

Answer by Audrey for How to dispatch a Redux action with a timeout?

$
0
0

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. It has been created for handling such a process.

  1. First config redux-thunk through documentation redux-thunk
  2. Second change your action creator this way:
const yourAction = millisecond => dispatch => {   setTimeout(() => {      dispatch({         type: 'YOUR_ACTIION_TYPE',         payload: yourWhatEverPayload      })   }, millisecond)}

Viewing all articles
Browse latest Browse all 15

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>