question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Reducers without immer

See original GitHub issue

Hey,

I’m aware of the position of the maintainers regarding disabling immer, as stated in #242 and #183. However, both of those discussions are the top google results when searching redux toolkit without immer. After some time, I realized that I could both keep RTK and add additional reducers without immer, which is required in edge cases for performance reasons*. I’ve created a gist with the solution, if you’re interested it could be nice to add the gist to the end of the discussion in #242, as that is the top-level result and I’m sure many people have been landing there without a clear way to solve their issue.

Here is the link: https://gist.github.com/romgrk/bb16d7b8d3827481d04eb535e8d1bc74

This issue can be closed.

* I’m not sure what goes on inside immer’s produce(), but in the edge-case I encountered, using a raw reducer took the runtime of a single action from ~200ms to ~2ms.

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:3
  • Comments:16 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
romgrkcommented, Jun 12, 2022

Freezing the data brings the performance to the same level as not using immer. I’ll send a PR to add the detail to the doc. I know it’s been said enough, but I really wish there was a way to use this module without immer; it adds too much magic to be comfortable to use.

image

1reaction
markeriksoncommented, Jun 12, 2022

Can you share a fully running sandbox or repo that shows this behavior, with a meaningful dataset?

Also, note that Immer does recursively freeze data by default. Can’t tell if that’s the issue here because there’s not enough of the perf capture shown in those screenshots. However, if that is the issue, note that you can do an Object.freeze(value) on the top-level object to prevent Immer from recursing:

https://immerjs.github.io/immer/freezing

Read more comments on GitHub >

github_iconTop Results From Across the Web

Writing Reducers with Immer | Redux Toolkit - JS.ORG
Redux Toolkit's createReducer and createSlice automatically use Immer internally to let you write simpler immutable update logic using "mutating ...
Read more >
Better Reducers With Immer - Smashing Magazine
In this article, we're going to learn how to use Immer to write reducers. When working with React, we maintain a lot of...
Read more >
Simplify Redux reducers with immer - Arnaud Dostes - Medium
It's that easy, the reducer using immer is the result of a function call to Immer's produce function that takes in a draft...
Read more >
Using Immer to Optimise Redux Reducer - Better Programming
Immer is a tiny package that allows you to work with immutable state in a more convenient way. Immer can be used in...
Read more >
Simplify Your Redux Reducers with Immer - DEV Community ‍ ‍
Immer to the rescue! Immer lets you "Create the next immutable state tree by simply modifying the current tree." What's that mean? Let's...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found