The Provider pattern puts related state and actions behind a React context and makes them available to descendants at any depth. A context can supply more than one value: a dark-mode toggle, for example, needs both the current mode and a function that changes it. section 2.1 section 2.1.1
Move state into a dedicated provider
Create a context, then let a provider own the state and pass an object containing isDarkMode and toggleDarkMode as its value. App can render <DarkModeProvider><Main /></DarkModeProvider>, while consumers read the object through a useDarkMode custom hook. This removes context wiring from App. Because App no longer owns the toggle state, its own re-renders no longer drive Main re-renders; components that consume the changing context still update. section 2.1.2 section 2.1.1
Scale the pattern deliberately:
- Use separate contexts at different levels for distinct concerns, such as authorization, application data, and UI controls; one provider need not own everything. section 2.1.5
- For larger data features, keep storage and manipulation in the provider and expose focused hooks for reads and actions. A data-provider example persists state to localStorage and separates its context, provider, and access hooks into files. section 8.3.2
- Watch update costs. Memoization can spare a non-consuming component from a parent re-render, while selectability targets unnecessary updates when consumers need only part of a context value. section 2.1.1 section 2.1
- When testing a consumer alone, wrap it in a provider supplying the values or callbacks it expects; otherwise it sees the context default. In React Developer Tools, inspect the nearest provider to manipulate its value rather than trying to edit it from a consumer. section 10.3.3 section 4.4.3
This is a flexible way to organize shared data, not a blanket reason to put all state in context. The examples use <MyContext.Provider> and useContext; React 19 also permits <MyContext value={...}> and use(). Comparisons with other state-management tools remain a separate design decision. section 2.1.1 section 2.1.5

