# State Fundamentals

> Local vs shared state, lifting state up, derived state, unidirectional data flow, and the difference between UI state and server data. Free notes, key...

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

Local vs shared state, lifting state up, derived state, unidirectional data flow, and the difference between UI state and server data.

Beginner · about 5 hours · difficulty 3/5

Learn first: [Components, Props & Styling](https://www.internhack.in/roadmaps/tracks/mobile/components-and-styling)

State is any data that can change and affects what is on screen. Most "state management" confusion disappears once you classify your state.

### Kinds of state

- **Local UI state**: is this dropdown open, what is typed in this field. Keep it in the component (`useState`, `StatefulWidget`, `remember`, `@State`).
- **Shared app state**: current user, theme, cart contents. Lives above the screens that need it.
- **Server state**: data owned by a backend (products, messages). It is a \*cache\* that can go stale; treat it differently (see networking).
- **Persisted state**: survives app restarts (settings, drafts).
- **Navigation state**: which screen is showing, owned by the router.

### Principles

- **Single source of truth**: each piece of data lives in exactly one place.
- **Lift state up** to the nearest common parent when two components need it.
- **Derive, don't duplicate**: compute totals and filtered lists from state rather than storing them separately.
- **Unidirectional flow**: state flows down, events flow up, and updates happen in one place.

### Pitfalls

Putting everything in a global store too early creates tangled code. Start local, lift when needed.

**Good enough to move on:** for any screen you can say which state is local, shared, server or persisted, and where each lives.

## Key concepts

- **Local component state**
- **Lifting state up**
- **Derived state**
- **Unidirectional data flow**
- **Server state vs client state**
- **Immutability and state updates**

## Mini project

Build a shopping cart across two tabs (catalogue and cart) where totals are derived, not stored, and item counts stay in sync.

## Check yourself

Why is storing both a list of items and a separate itemCount in state a bug waiting to happen?

## Free resources

- [React: Managing state](https://react.dev/learn/managing-state) (React)
- [Flutter: State management](https://docs.flutter.dev/data-and-backend/state-mgmt) (Flutter)
- [Compose: State and Jetpack Compose](https://developer.android.com/develop/ui/compose/state) (Android Developers)

Previous: [Deep Links, Universal Links & App Links](https://www.internhack.in/roadmaps/tracks/mobile/deep-linking) · Next: [App-wide State Tools](https://www.internhack.in/roadmaps/tracks/mobile/state-libraries)

## 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)
