0

I was working on creating the react-redux application. But stuck on the point why we shouldn't call the async function (for API calling) in the component method like componentWillMount etc? Why I've to use the middleware like redux-thunk & saga? Why we cannot call the API request from the action and based on that result, we call the reducer? Is it the bad idea? I didn't understand deeply about this. Can you please help me out to understand the concept of API calling in redux?

Shubham
  • 1,163
  • 2
  • 12
  • 36
  • call async API in in redux without using redux-thunk/saga.You . will get warning / error in console.It help u. – RIYAJ KHAN Feb 26 '18 at 05:23
  • @RIYAJKHAN, Thanks for your help and I really appreciate your input. But I think this is not the proper clarification of the question. – Shubham Feb 26 '18 at 05:28
  • 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) – RIYAJ KHAN Feb 26 '18 at 05:43
  • https://stackoverflow.com/questions/35411423/how-to-dispatch-a-redux-action-with-a-timeout/35415559#35415559 – RIYAJ KHAN Feb 26 '18 at 05:43

1 Answers1

0

As far as I see it, you can call async functions anywhere, including in componentWillMount. What a middleware like redux-thunk does, is to add IDs in the dispatched actions, 'ordering' them, avoiding race conditions such as the one that is described in Writing Async Code in redux

Yossi
  • 5,577
  • 7
  • 41
  • 76