React Context in Next.js

Context is useful for client-side values that need to be shared across a subtree, such as theme preferences or UI state.

Because Context uses client-side React behavior, providers often need to be Client Components. The provider can then wrap only the part of the tree that actually needs the context.

Avoid placing a huge global provider around the entire application if only a small section needs it.

Key Takeaways
  • Context is useful for shared client-side state.
  • Keep providers as narrow as practical.
  • Context is not automatically a replacement for server-side data fetching.