-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uncaught TypeError: Cannot freeze #406
Comments
Since recoil is experimental, you would have more stable results by only using primitives. This is also a good practice for recoil's state persistence. |
Having the same issue |
Apart from not using objects, is there a way to safely use objects, similar to how an array is used in the Documentation
|
You can use objects, but you can expect lesser errors when using primitive ones. |
Recoil freezes stored values for atoms in part to help ensure that all state changes are visible and propagated as updates through the data-flow graph. If stored values are mutated in an attempt to change state it won't be tracked or update dependencies. To help catch this, we deep freeze objects in development. However, there are situations where mutable objects may need to be used as values that don't logically represent Recoil state changes. You can use the |
Thank you @cybervaldez and @drarmstr for the explanation!, I'll be trying the |
When using the setter function to update a value of an atom you cannot pass any object as
Object.freeze(value)
can throw an error in some cases.In my case I am passing a Firebase user to update the value of an atom but I am having
Uncaught TypeError: Cannot freeze
error. The error happens here:Recoil/src/util/Recoil_deepFreezeValue.js
Line 65 in e018c3a
Example
Another example would be that passing something like
location.ancestorOrigins
will also throw the same error.What would be the solution? Should I just take some of the properties and create a new simpler object and pass it to the setter function or somehow convert the entire user object into a freezable object?
The text was updated successfully, but these errors were encountered: