Reccommended approaches for actions, selectors, and tracked state #80
MatthewScholefield
started this conversation in
General
Replies: 1 comment
-
Here a few examples we have in Plate: https://github.com/search?q=repo%3Audecode%2Fplate%20createZustandStore&type=code |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello! As a relative newcomer to
zustand
andzustand-x
, I feel a little lost about the "recommended" approach to build a real world app usingzustand-x
. Specifically, I'm wondering:set.state(draft => { draft.foo = 'bar'; draft.baz = 'boo'; })
orset.foo('bar'); set.baz('boo')
. Is there a difference between the two (in terms of atomicity or performance)? I tend towards using the former since it supports easy nested assignment likedraft.foo[0].fooz = 'bar'
. Is it an anti-pattern to just have all actions usingset.state(draft => ...)
?zustand
we could easily create on-the-fly selectors likeconst isEmpty = useMyStore(x => x.myArr.length === 0)
. Is there a simple way to do this withzustand-x
? (ie. is the suggested equivalentmyStore.useTracked.myArr.length === 0
?)Regardless, I'm finding
zustand-x
very useful even just for the typing aspect alone, but I'd appreciate if anyone could offer their insights or opinions on these ambiguities mentioned above. I think it'd be awesome to have a tiny, yet complete toy example that shows off the suggested way to design an app usingzustand-x
.Beta Was this translation helpful? Give feedback.
All reactions