Search code examples
javascriptreactjsreduxreact-redux

How many methods are there to use React-Redux? Redux-thunk vs Redux-Saga?


I am very confused with Redux as I am learning different methods. I want to know how many more methods are there like redux-Thunk, redux-saga. All of them use a different function like CreateSlice. Which methods are suitable for small projects and what is the main difference between them.


Solution

  • I'd recommend giving the official Redux Style Guide a read.

    Generally: at this moment, there are 14818 redux-themed packages available on npm. It's pretty impossible to name them all ;)

    But also, there are clear recommendations by the Redux team:

    • use Redux Toolkit
    • if you only need api data without further manual logic, use createApi form RTK-Query
    • if you need manual logic attached to that, use createAsyncThunk or just thunks. Only if those are not enough, turn to other middlewares like saga
    • sagas are very overused, most of the time not needed and add unneccesary complexity. We are currently building an action-listener-middleware that covers about 75% of the saga functionality with a simpler api (those 25% functionality left after that are the real saga use case, but probably only 2-5% of users ever need those).
      That said, most people would not even need that and could probably do everything they are using sagas for with thunks instead, which are much more simple.

    There are also other libraries like redux-observable etc. Those have a non-deniable market share in the single-digit percentages, but if you are just getting started, go by the official recommendations.

    Best get started by reading the official Redux Tutorial. It should cover 90% of all the Redux knowledge you'll ever need.