-
Notifications
You must be signed in to change notification settings - Fork 1
Description
Hi,
I'm commenting a bit on the Zustand discussion boards (pmndrs/zustand#2830), trying to find a way to get great performance with many components listening to one Zustand store. I'm trying to not only reduce re-renders, but also reducing the number of selector calls that will have to be done for each component, i.e., to have components subscribe on a more granular basis to parts of the state. A solution is of course to use atoms/signals instead, but I like the more centralized model of a Zustand store, so I've been looking for ways to do it without rewriting everything in Jotai or resorting to convoluted workarounds.
Jotai-zustand could of course be a good solution, and I can use atomWithStore
and create derived atoms and then useAtom
to create a more direct subscription to that atom's value (saving a lot of work done by selector calls).
But then looking at your code base I came across a few interesting functions that are exported, and that could hint at some other solution, namely create
and atomWithActions
— these seem to create a Zustand-like useStore interface backed by an atom, is that right?
I thought perhaps I could create a hybrid/mutant Zustand store that directly supports deriving atoms from it (or within it) — and while the atom/store they create seems to have a useStore
type interface, it doesn't have the getStore
/setStore
of the vanilla stores, and it doesn't expose the underlying atoms?
What is the purpose of these, and do you have any thoughts on how to achieve the performance of Jotai Atoms (avoid selector calls) while keeping the programming model of Zustand?