Make a store reactive to changes in another store #1586
-
I have two stores that I am not even sure should be two separate stores. One holds settings entered by the user and the other is the actual state variables being manipulated. I have split them into two stores just to reduce the size of the store. Keeping things small has always worked for me but I am not sure if this goes against the intended use of Zustand. So, I have this config store:
...and I have this store, where I want the selected
The
..but ideally this would happen in the store itself rather than in some random component. Is there a way to link these two? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Zustand is unopinionated, and you can do what you can do. That said, Zustand is not designed for coordinating multiple stores. So, in general, a single big store is preferred, if such coordination is required, like changing both things at once. If you prefer keeping things small, you may want to try https://github.com/pmndrs/jotai or https://github.com/pmndrs/valtio. btw, I have an experimental project derive-zustand, but it may not fit your needs. |
Beta Was this translation helpful? Give feedback.
Zustand is unopinionated, and you can do what you can do.
You could use
.subscribe()
instead of useEffect.That said, Zustand is not designed for coordinating multiple stores. So, in general, a single big store is preferred, if such coordination is required, like changing both things at once.
If you prefer keeping things small, you may want to try https://github.com/pmndrs/jotai or https://github.com/pmndrs/valtio.
btw, I have an experimental project derive-zustand, but it may not fit your needs.