What is the Context API for state management?
Answer
The React Context API enables sharing values between components without prop-drilling. Create: const ThemeContext = React.createContext("light");. Provide: <ThemeContext.Provider value="dark"><App /></ThemeContext.Provider>. Consume: const theme = useContext(ThemeContext);. For mutable state: combine with useState or useReducer: const [state, dispatch] = useReducer(reducer, initialState); <StateContext.Provider value={{ state, dispatch }}>. Performance issue: every component consuming the context re-renders when the context value changes — even if it only uses a small part of the value. Solutions: split contexts by concern, memoize with useMemo, or use a state management library with selective subscriptions. Best uses: theme (light/dark), locale, current user, feature flags. Avoid for: frequently changing state (cartItem count on every keystroke), complex state with many derived values. Context is a low-overhead, built-in solution for sharing configuration and rarely-changing state.