r/reactnative • u/FahadAppMaster • 8h ago
Question What made you switch state management in React Native, or stick with your first pick?
I started with Redux and it worked fine for a while, but the boilerplate started to feel heavy for a smaller app. I tried Zustand next and liked how much simpler the setup felt. For those of you who switched, what finally pushed you to change? And if you stayed with your first pick, what kept you there?
4
Upvotes
4
u/praxiz_c 7h ago
For global state management I was first introduced to Redux, which was great, but as OP says, it's a lot of work to get set up, and maintain. When I tried Redux Toolkit however, I've never needed anything else. Just type in something like this in a new component and you're all set.
2
u/OYM-bob 4h ago
We got out of global state manager. No redux, no zustand. Each screen has its request, and we have cache on request... I didn't trust the process, but it became SO.MUCH easier, devx friendly, and ui/ux clean. I'll never use state manager ever again
1
u/21void 6h ago
zustand. easy for me to reason with after AI generate it
1
u/ChronSyn Expo 7h ago
I started with MobX and mostly stayed there because it's just decorated getters and setters. Nowadays, decorators aren't needed, and you just have
makeAutoObservable(this)in your store class constructor.Essentially, every state store file include the class implementation, but also the exported instance
e.g. export const singleton = new MyStore().Then there's a store provider file which exports an object containing all those singletons as named values (so it's easy to reference them), a store context provider against that object, and a
useStoreshook against that context provider.This means that when the provider is invoked at the start of the react tree, all those store singletons are initialised too. Everywhere else in the React Tree uses the
useStoreshook, and anywhere that's not in the scope of React uses the exported singleton object from the store provider instead.Essentially, I only ever end up with a single instance of the stores which avoids the situation of 'react didn't re-render because it was calling a different store class instance'. If I happen to need another separate instance of a store, I still have the option of creating one via the class itself and referencing it locally, but that's not something I think I've ever needed because of the larger architecture approaches that play to the strengths of the provider + singleton pattern.
Some people will say that classes in JS are a monstrosity, but they're a tool like anything else and I feel they're the right tool for this situation.
Never liked redux because every implementation I saw was obtuse and frustrating to follow. I'm sure it made some people feel smart for using it, but I've always been a 'beauty is in the simplicity' sorta person.
1
u/anthony-ball 6h ago
What changed it for me wasn't Redux vs Zustand so much as realizing most of what I had in the store was server data. On a wallet app I worked on, balances, positions and quotes all moved into TanStack Query with sensible staleTime and invalidation after a swap, and what was left for Zustand was tiny: selected account and chain, a few UI flags, and the in-progress swap form. Once the store is that small the library barely matters, though Zustand's selectors made it easy to keep the price-ticking screens from re-rendering everything. I'd only reach back for Redux Toolkit if the team already knows it well or wants its devtools and middleware.
1
u/bsmayer_ 6h ago
I use Jotai nowadays for local state and React Query for server-side state. In the past I was mainly into MobX, but Jotai feels more natural with the current React architecture
1
u/Aggravating_Dot9657 4h ago
Tanstack React Query and managing cache time/invalidation for server state. I will never go back. So much easier than maintaining a store that also needs to manage and export its query functions. All consumers need to do is invalidate cache. Pagination and caches by filtering/sorting are also easy to manage. It is a dream.
Local state zustand does everything I need and also manages persistence. I've had no reason to stop using it.