Next.js
/Beginner
Context API in Next.js
Definition
Using React Context to share global state (like Light/Dark theme or User Authentication status) across an entire Next.js application.
Explain Like I'm New
Context lets you teleport data. Instead of passing `isDarkMode` down through 10 layers of components (prop drilling), you wrap your app in a `<ThemeProvider>`. Any component deep inside can instantly grab the theme.
Real World Example
Providing the current logged-in user's data to the Navbar, the Sidebar, and the Settings page simultaneously.
Common Use Cases
- •Theming
- •Auth state
- •UI toggles (Sidebar open/close)
Interactive Example
Interview Questions
basic
- Can you create a Context Provider inside a Server Component?
intermediate
- If you wrap your entire `app/layout.tsx` in a Client Component `<Provider>`, does it force every page in your app to become a Client Component?