DEV Community

Discussion on: RTK Query vs Redux Saga: What to choose for your next project?

Collapse
 
markerikson profile image
Mark Erikson • Edited

Hi, I'm a Redux maintainer.

Note that we specifically recommend against using sagas in almost all cases!

Sagas are a very powerful tool, but almost no apps need that power. Additionally, sagas have always been a poor choice for data fetching use cases.

(I'll also note that there's no reason to use the legacy createStore API - you should always use RTK's configureStore, and if you are using sagas you can add them to configureStore via the middleware option.)

Today, RTK Query solves the data fetching use case, and the RTK "listener" middleware handles the reactive logic use case - it can do almost everything sagas can, but with a simpler API, smaller bundle size, and better TS support.

I recently did a talk on The Evolution of Redux Async Logic, where I covered what each tool does and when to use it. I'll paste the summary slide here:

Our Recommendations Today

What use case are you trying to solve?

Data Fetching
  • Use RTK Query as the default approach for data fetching and caching
  • If RTKQ doesn't fully fit for some reason, use createAsyncThunk
  • Only fall back to handwritten thunks if nothing else works
  • Don't use sagas or observables for data fetching!
Reacting to Actions / State Changes, Async Workflows
  • Use RTK listeners as the default for responding to store updates and writing long-running async workflows
  • Only use sagas / observables if listeners don't solve your use case well enough
Logic with State Access
  • Use thunks for complex sync and moderate async logic, including access to getState and dispatching multiple actions
Collapse
 
thisisgazzar profile image
Mohamed Elgazzar

Hi Mark, thanks for your comment!

Yeah, I actually mentioned in the end that RTK Query is the recommended approach, and I also added that createStore is now deprecated.

I will modify the post and make things clearer!