# App-wide State Tools

> Choose and use a shared-state tool for your stack: Zustand or Redux Toolkit, Riverpod or Bloc, ViewModel with StateFlow, or Observable. Free notes, key...

Canonical: https://www.internhack.in/roadmaps/tracks/mobile/state-libraries
Last updated: 2026-11-28

Choose and use a shared-state tool for your stack: Zustand or Redux Toolkit, Riverpod or Bloc, ViewModel with StateFlow, or Observable.

Intermediate · about 8 hours · difficulty 3/5

Learn first: [State Fundamentals](https://www.internhack.in/roadmaps/tracks/mobile/state-fundamentals)

Once several screens share data, you want a predictable place to keep it. Each stack has a few popular options; pick one and learn it well rather than sampling all of them.

### By stack

- **React Native**: React Context for rarely changing values (theme, auth); **Zustand** for simple global stores; **Redux Toolkit** for large teams wanting strict patterns and devtools. Use **TanStack Query** for server data instead of putting API responses in a store.
- **Flutter**: **Riverpod** (recommended modern choice), Provider, or **Bloc/Cubit** for event-driven, very testable flows.
- **Android**: `ViewModel` exposing `StateFlow<UiState>`, collected in Compose with `collectAsStateWithLifecycle()`.
- **iOS**: `@Observable` classes (Observation framework) injected with `@Environment` or passed down.

### What good looks like

- Screens read state and dispatch intentions (`addToCart(id)`), never mutate the store directly from the UI.
- Business logic lives in the store/ViewModel, which makes it unit-testable without UI.
- Subscriptions are granular so one change does not re-render the whole app.

### Pitfalls

- Context holding fast-changing values re-renders every consumer.
- Duplicating server data in a global store and then fighting to keep it fresh.

**Good enough to move on:** your cart logic lives in one store/ViewModel with unit tests, and screens are thin.

## Key concepts

- **React Context**: For low-frequency values
- **Zustand**: React Native default pick
- **Redux Toolkit**
- **Riverpod or Bloc**: Flutter
- **ViewModel and StateFlow**: Android
- **Observable and Environment**: SwiftUI
- **Keeping business logic out of views**
- **Avoiding unnecessary re-renders**

## Mini project

Refactor your cart app so all cart logic lives in a store or ViewModel, add persistence of the cart, and write three unit tests for it.

## Check yourself

Why should API responses usually live in a query cache rather than a global store like Redux or Zustand?

## Free resources

- [Zustand](https://zustand.docs.pmnd.rs/) (pmndrs)
- [Redux Toolkit](https://redux-toolkit.js.org/) (Redux)
- [Riverpod](https://riverpod.dev/) (Riverpod)
- [Android: UI layer and state holders](https://developer.android.com/topic/architecture/ui-layer) (Android Developers)

Previous: [State Fundamentals](https://www.internhack.in/roadmaps/tracks/mobile/state-fundamentals) · Next: [Hooks, Effects & Platform-specific Code](https://www.internhack.in/roadmaps/tracks/mobile/rn-hooks-and-platform)

## More in Navigation & State Management

- [Navigation Patterns](https://www.internhack.in/roadmaps/tracks/mobile/navigation)
- [Deep Links, Universal Links & App Links](https://www.internhack.in/roadmaps/tracks/mobile/deep-linking)
- [State Fundamentals](https://www.internhack.in/roadmaps/tracks/mobile/state-fundamentals)
- [App-wide State Tools](https://www.internhack.in/roadmaps/tracks/mobile/state-libraries)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [Mobile App Developer Roadmap](https://www.internhack.in/roadmaps/tracks/mobile)
