Course contentsShow
← React
Lesson 839 of 2,39622. Context PerformanceFree lesson

Identifying Independent State Domains

How to analyze your state to find pieces that change independently and serve different consumers.

Identifying Independent State Domains

What you'll learn: How to spot which pieces of state change independently and serve different parts of your app — so you can split them into separate contexts.

The Problem with Dumping Everything in One Context

When you put all your application state into a single context (the anti-pattern from the previous lesson), every state change triggers re-renders in every component that reads any part of that context. Even if a component only cares about the user's theme preference, it re-renders when the shopping cart updates.

What Are Independent State Domains?

State domains are groups of related data that:

  • Change for different reasons
  • Serve different consumers
  • Have no tight coupling to each other

Think of your state like different departments in a company. HR doesn't need to know when Sales updates a customer order. They operate independently.

How to Identify Separate Domains

Ask yourself:

  1. Does this state change independently? (Theme changes rarely; notifications change constantly)
  2. Who consumes it? (Only the header needs user info; only one modal needs form data)
  3. Do they update together? (If A always changes with B, they're one domain)

Examples of Natural Domain Splits

  • User authentication (login state, user profile) — changes on login/logout
  • UI preferences (theme, language) — changes rarely, read by layout components
  • Shopping cart — changes frequently, read only by cart-related components
  • Notifications — changes very frequently, read only by notification bell

Each of these deserves its own context because they have different update patterns and different consumers.

Key Takeaway: Analyze your state to find pieces that change independently and serve distinct groups of components — these are candidates for separate contexts, reducing unnecessary re-renders.