Search code examples
react-reduxredux-saga

Do I have to use redux saga to fetch from an API if I don't need to store the data in the redux store?


I'm already familiar with how Redux saga works, my question is more around best-practices. I have an application in which I have actions which are dispatched, then intercepted by saga where it runs an API call, and then the saga dispatches another action, usually storing the data to the redux store.

My question is, what if I just need to call an API from my front-end but don't need to store the data in the redux store? Do I just call my API from the front-end directly (e.g. with axios/fetch API?) or do I have to use saga to fetch it?

In the second case where I use saga, how do I pass the data up from saga to the component (without adding the response data to the redux store)?


Solution

  • If you don't need the data in the store (component state is enough) then just querying the data directly from the component (via react-query or some other data fetching layer) is "better" in the sense that you don't have to "globalize" that data in your application state (don't need actions/reducers/selectors)