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

When Not to Split: Tightly Coupled State

Recognizing when state truly changes together and splitting would add unnecessary complexity.

When Not to Split: Tightly Coupled State

What you'll learn: How to recognize when state genuinely belongs together and splitting it would create more problems than it solves.

The Over-Splitting Trap

After learning to split contexts for performance, it's tempting to split everything. But context splitting has a cost: more providers, more boilerplate, more imports, and more complexity. The art is knowing when state is tightly coupled — meaning parts always change together or depend on each other — and should stay unified.

Recognizing Tightly Coupled State

Ask yourself:

  • Do these values always update together in the same action?
  • Does one value determine the validity or meaning of another?
  • Would splitting require synchronization logic to keep them consistent?

Example: A shopping cart's items and totalPrice are tightly coupled. They update together on every add/remove action. Splitting them into separate contexts means duplicating the calculation logic or risking inconsistency. The performance "win" is imaginary — both change simultaneously anyway.

Another example: Form state with firstName, lastName, and fullName (derived from both). These are interdependent. Splitting creates coordination headaches for zero benefit.

When Unity is Clarity

If components consuming your state typically need most of it, keeping it together is clearer. A single useCartContext() is simpler than useCartItems() + useCartTotal() + useCartCount() when most cart displays need all three.

Split contexts when parts of state change independently and are consumed by different component subtrees. Don't split when doing so forces you to choreograph multiple contexts that should be one logical unit.

Key Takeaway: Context splitting optimizes performance only when state updates independently; tightly coupled state that always changes together should remain in a single context for simplicity and maintainability.