Search code examples
reactjsreact-reduxredux-sagaredux-thunkredux-middleware

When should I use Redux Saga instead of Redux Thunk, and when should I use Redux Thunk instead of Redux Saga?


The question is different from the past which is why. The question for this one is When. Since both are good frameworks by themselves the question is when should I use thunk than saga. Because one of my friend keeps insisting me to use saga in our app but no apparent reason why. Thanks ahead


Solution

  • Based on some readings and my experience...

    Use Thunk instead of Saga for simple and trivial tasks like:

    • AJAX calls
    • data polling and only if they are started directly by the user interaction.

    Use Saga for

    • intertwined tasks, the login example of the docs is perfect
    • flows with a lot of steps and waitings for other conditions to happen ("finite-state machine" flows)
    • tasks that work in the background and proceed independently from the user interaction (or a mix of background/interactions)