Context API for global UI state

9485
0

While React Query handles server state, I use Context API for client-side UI state like theme, sidebar visibility, or current user. Each context lives in its own file with a custom hook for consuming it. The context provider wraps the app at a high level and provides both state and updater functions. I avoid putting too much in context—only truly global state belongs here. For component-local state that's shared with a few children, prop drilling or composition is clearer. The useReducer hook works well for complex state transitions within a context. This pattern gives centralized state management without Redux's boilerplate for simple use cases.