2022-05-26
2788
#redux
Joseph Mawa
113587
May 26, 2022 â‹… 9 min read

Redux Toolkit’s new listener middleware vs. Redux-Saga

Joseph Mawa A very passionate open source contributor and technical writer

Recent posts:

Integrating Django Templates With React For Dynamic Webpages

Integrating Django templates with React for dynamic webpages

Create a dynamic demo blog site using Django and React to demonstrate Django’s server-side functionalities and React’s interactive UI.

Kayode Adeniyi
Apr 18, 2024 â‹… 7 min read
Using Aoi Js To Build A Bot For Discord

Using aoi.js to build a bot on Discord

Explore how the aoi.js library makes it easy to create Discord bots with useful functionalities for frontend applications.

Rahul Padalkar
Apr 17, 2024 â‹… 9 min read
Web Components Adoption Guide: Overview, Examples, And Alternatives

Web Components adoption guide: Overview, examples, and alternatives

Evaluate Web Components, a set of standards that allow you to create custom HTML tags for more reusable, manageable code.

Elijah Asaolu
Apr 16, 2024 â‹… 11 min read
Using Aws Lambda And Aws Cloudfront To Optimize Image Handling

Using AWS Lambda and CloudFront to optimize image handling

Leverage services like AWS Lambda, CloudFront, and S3 to handle images more effectively, optimizing performance and providing a better UX.

Nitish Sharma
Apr 12, 2024 â‹… 12 min read
View all posts

2 Replies to "Redux Toolkit’s new listener middleware vs. Redux-Saga"

  1. Hiya, I’m a Redux maintainer and the person who drove development of the listener middleware. Very nice post!

    A few quick thoughts:

    I actually covered our current recommendations for which Redux middleware to use when in my recent Reactathon talk “The Evolution of Redux Async Logic”: https://blog.isquaredsoftware.com/2022/05/presentations-evolution-redux-async-logic/ .

    As a TL;DW: use RTK Query for data fetching; thunks for logic that just needs to talk to the store; and listeners if your code needs to react to actions or state changes. Only reach for sagas as a last resort if no other tool works.

    Per the bundle sizes table – this is a bit confusing and misleading, because it’s comparing two specific APIs vs the entire RTK library. In addition, that “12.7K min+gz for all of RTK” _also_ includes the size of Immer, Reselect, and the Redux core.

    Also, RTK _does_ tree-shake. If I just use `configureStore` and `createSlice`, you won’t pay the cost of including `createAsyncThunk`, `createEntityAdapter`, or `createListenerMiddleware`. So, yes, the _entire_ lib is 12.7K min+gz including dependencies, but most apps aren’t using every single API in RTK.

    I’m actually very curious where you got the “6.6K min” size for the listener middleware. With how Bundlephobia works, and because we ship our package as a single file per module build artifact, that isn’t broken out separately. When the middleware was still a standalone package for alpha testing, it looked like the “modern” bundle file for that build was coming in right at 4K min

    I just did some hand-inspection of the `cjs.production.min` and `esm.modern.min` build artifacts in our published package, and pulled out _just_ the listener middleware code. Looks like the “ESM modern” code is only 3.8K min, and the “CJS compat” code is 5.1K min. Running each of those through GZIP, I get 1.7K min+gz for “modern”, and 2K min+gz for “CJS compat”. So, the table isn’t too far off, but actual code included in the bundle _should_ be a bit better than what’s listed 🙂

    I appreciate you taking the time to write this article, and put together the comparisons. Glad to hear that you’ve found the listener middleware “easy to learn”!

  2. Hi @Acemarke, Joseph here. Thanks for reading and taking time to provide feedback. I do agree Bundlephobia’s estimates are far from precise. I will update the article and highlight it in the corresponding section. And include the other points you raised. I believe readers will find them useful as well.

    Thanks once again for your time.

Leave a Reply