Search code examples
reactjsredux

When to call API in React and when to call API in Redux actions


Simply,

I just wanted to Know when should I call the API in redux actions using redux-thunk and when should I directly call it in react Component (in Constructor or ComponentDidMount ),

It would be really helpful to know which to use when.


Solution

  • Use Redux

    When you want your API Response to be used across multiple parts of your application .

    Use ComponentDidMount

    when the API response is specific only to that component and its not needed to be shared across the application .