0

Im using redux thunk in a project and I thought of a question. Wouldn't it be the same to make asynchronous calls in the container and then dispatching the result to redux, vs using thunk to make the asynchronous call in an action creator? The only reason I see to use thunk would be less duplication of code as each container would be responsible for the asynchronous code vs it being encapsulated in an action creator. Is there any other specific reason to use asynchronous action creators?

Pbb
  • 408
  • 6
  • 21
  • 1
    "This makes them portable and easy to test." [https://redux.js.org/basics/actions#action-creators](https://redux.js.org/basics/actions#action-creators) – jcal Jan 15 '19 at 23:06
  • my question is why you should have an asynchronous action creator call a synchronous action creator to return an action, vs, an asynchronous action creator returning an action itself. your link just described the purpose of action creators in general – Pbb Jan 15 '19 at 23:17
  • 1
    @Peter your question doesn't make much sense based on the code you show. If `saveResult(res)` returns the same thing as `{ACTION OBJECT}` than the only reason to use the first pattern is for exactly what @jcal linked to – Matthew Herbst Jan 15 '19 at 23:40
  • edited with a new question – Pbb Jan 16 '19 at 08:39
  • Possible duplicate of [How to dispatch a Redux action with a timeout?](https://stackoverflow.com/questions/35411423/how-to-dispatch-a-redux-action-with-a-timeout) – jcal Jan 16 '19 at 09:15

0 Answers0