Skip to content
Discussion options

You must be logged in to vote

Well, actually, all the states you get from useStore are read-only, right?

So is it reasonable for zustand to wrap Object.freeze() by default? Are there any other problems?

@dbritto-dev

Actually, only primitives are readonly (you can't mutate them, just reassign them) in JS. What you are doing is mutating an object directly (which is wrong in a react context). BTW, what you get from useStore is not the store itself if just the result of a given selector, even if the selector if the "store" itself. Nothing avoids mutate that result (object) directly but is wrong in a react context due to that mutation only exists on the scope component so if you read the store on another component the va…

Replies: 3 comments 4 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
4 replies
@dai-shi
Comment options

@dbritto-dev
Comment options

@vaynevayne
Comment options

@dbritto-dev
Comment options

Answer selected by dbritto-dev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #1884 on June 20, 2023 12:03.