r/reactnative • • 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

14 comments sorted by

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.

const {user, products} = useAppSelectors(); 

3

u/FahadAppMaster 6h ago

Redux Toolkit really does fix the worst parts of plain Redux. That one hook pulling exactly what you need is a clean setup.

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/FahadAppMaster 2h ago

That is a good point. Keeping the request and cache close to each screen sounds much simpler than syncing a global store. Did you find anything that still needed shared state, or did the per-screen setup cover it all?

1

u/21void 6h ago

zustand. easy for me to reason with after AI generate it

1

u/FahadAppMaster 6h ago

That is good to hear. Zustand does feel easy to follow once the store is set up. Do you find the AI generated code still easy to debug when something goes wrong?

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 useStores hook 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 useStores hook, 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/FahadAppMaster 6h ago

That singleton setup sounds really clean. Having one instance and reaching it from anywhere, inside or outside React, seems like a big practical win. Did MobX stay simple for you as the app grew?

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/FahadAppMaster 5h ago

That is a really helpful way to look at it. Moving the server data out first makes the choice of store feel a lot less important. Did that split change how you think about what belongs in the store at all?

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/FahadAppMaster 5h ago

That split makes a lot of sense. Keeping server state in React Query and local state in Jotai sounds like a clean setup. Did Jotai feel like a big change after MobX, or was it a pretty easy switch?

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.

1

u/FahadAppMaster 3h ago

That lines up with what a few people here said about splitting server state from local state. Letting the cache layer handle invalidation and keeping Zustand for the local stuff sounds like a clean split. Thanks for explaining it.