0Pricing
React Academy · Lesson

Context Selector Pattern

Implement a simple selector hook that only re-renders when a slice of context changes.

Welcome

In this lesson you will implement a context selector hook that subscribes a component to only a slice of context state, preventing re-renders when unrelated parts of the context change.

The Selector Problem

useContext re-renders when ANY part of the context changes. If a component only needs the user's name but the context also holds a notifications list, adding a notification re-renders the name component unnecessarily.

All lessons in this course

  1. Splitting Contexts to Limit Re-renders
  2. Memoizing Context Values with useMemo
  3. Context Selector Pattern
  4. When Not to Use Context
← Back to React Academy