React State & Context in React Native

Use useState, useReducer and Context correctly in a React Native app, and know when to stop.

React's built-in tools cover more than most people expect. Learn their limits before reaching for a library.

Core concepts

  1. useState and useReducer: Use useState for simple values and useReducer when updates follow rules, such as a multi-step form or a game state. — React docs
  2. Lifting state up: When two siblings need the same value, move it to their nearest common parent and pass it down. — React docs
  3. Context: Context shares a value with a whole subtree without prop drilling. Split contexts by purpose so a change in one does not re-render unrelated consumers. — React docs
  4. Derived state: Compute values from existing state during render instead of storing duplicates, for example const total = items.length. — React docs

Concept videos

YouTube channels and searches for these topics. On a large screen they open in the reading panel next to the roadmap.

Explanation

When Context becomes a problem

A context value that changes often re-renders every consumer. If you see unrelated screens re-rendering, move that data to a store with selectors.

Keep effects honest

Effects synchronise with outside systems. Do not use effects to copy one state into another; derive it instead.

What Is It?

These are React's built-in ways to hold and share data in components.

Why Should I Care?

Using the simplest tool keeps code small and easy for an agent to modify.

Real World Analogy

State is a notebook each component carries, and Context is a notice board on the wall for everyone in the room.

Visual Mental Model

text
useState (one component) -> lift up (siblings) -> Context (subtree) -> store (app)

Smallest Possible Example

tsx
const ThemeContext = React.createContext<'light' | 'dark'>('light');

export function useTheme() {
  return React.useContext(ThemeContext);
}

Common Mistakes

❌ Storing derived values in state.

They go out of sync with their source; compute them during render.

❌ One giant context.

Split by concern so updates stay local.

Build This Mini Project

Build a settings screen with theme and notification toggles using Context for theme and local state for the form.

Prompts for Cursor, Claude Code & Codex

Paste these into Cursor, Claude Code, Codex, or any coding agent. Replace the bracketed parts with your app details, and keep the agent in plan mode first so you review the approach before it edits files.

Remove derived state

text
Review components in [folder] for state that duplicates other state or props. Replace it with values derived during render and explain each change.

Split a context

text
This context holds unrelated values: [paste]. Split it into focused contexts with custom hooks and update consumers without behaviour changes.

Rules, databases & blogs to use

Resources

Threads in the same domain as this chapter — go deeper on iHateReading without leaving the roadmap.

How to build an AI chat app with Vercel AI SDK and Firebase cover

How to build an AI chat app with Vercel AI SDK and Firebase

Chat UI, streaming and backend wiring for an AI feature.

Agent harnessing: the part of building AI agents nobody talks about cover

Agent harnessing: the part of building AI agents nobody talks about

Loop, tools, memory, sandbox, and tracing live in your code — not the model weights.