Skip to content

Method to turn off freezing when using immer with useSelector()? #1189

Answered by markerikson
njradford asked this question in Q&A
Discussion options

You must be logged in to vote

There's a couple different answers here.

First, Immer technically does export a way to disable freezing, with setAutoFreeze: https://immerjs.github.io/immer/freezing

However, I'd strongly recommend leaving that as-is. It not only catches bugs and prevents accidental mutations, the dev mode middleware rely on checking for frozen state as a bailout signal to speed up those checks.

Beyond that, it sounds like the frozen state is actually doing its job here. Developers shouldn't be "adding properties to objects", because those are the original objects from state. Adding properties to those objects would be an actual mutation, which is wrong.

It also sounds like this situation involves devs "c…

Replies: 1 comment 6 replies

Comment options

You must be logged in to vote
6 replies
@phryneas
Comment options

@markerikson
Comment options

@njradford
Comment options

@phryneas
Comment options

@njradford
Comment options

Answer selected by njradford
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants