Replies: 2 comments 11 replies
-
@beorn you are looking for |
Beta Was this translation helpful? Give feedback.
-
@dbritto-dev As far as I understand, even in this case, all of the 10,000 Counter2 components are listeners to the entire store state, so Zustand would have to do work to determine whether they should re-render, no? It has to iterate through 10,000 selectors and see if anything changed, on every store change. I'm trying to short circuit this work so the Counter2 components listen directly to state.counter2 — there's no need to do any work related to them (involving iterating over 10,000 objects) if state.counter2 didn't change. |
Beta Was this translation helpful? Give feedback.
-
Hi,
I have an app with a lot of components and I would like to make it as performant as possible, i.e., avoiding unnecessary re-renders and selectors calls altogether.
I know I can rewrite the app to use atoms/signals (or bridge into jotai with atomWithStore) so that components can subscribe to individual atoms/signals — but is there a canonical way to do this in zustand?
For example:
Is there a way to ensure that Counter1 is not re-rendered and its selector function isn't even called if counter2 is updated? Imagine I have 10,000 Counter2 components — I'd like for them not to do any work if state.counter1 is updated, but to my knowledge they will each have at least their selector functions run.
I could imagine something like:
Beta Was this translation helpful? Give feedback.
All reactions