ForgeFrontend — Prepare, Practice, Crack
Secure checkout
Lifetime access
Instant Drive delivery
Free updates forever

Prepare · Practice · Crack

What is the Context API and what problem does it solve?

Quick answer

Context provides a value to an entire subtree without prop drilling. Components read it with useContext.

In detail

Prop drilling — passing a prop through many components that don't use it — is painful for global data like theme, current user, or locale. You create a context, wrap part of the tree in its Provider, and any descendant reads it via useContext. Every consumer re-renders when the Provider value changes.

const ThemeCtx = createContext('light');
<ThemeCtx.Provider value="dark"><Toolbar /></ThemeCtx.Provider>
// deep inside:
const theme = useContext(ThemeCtx); // 'dark'

Why interviewers ask this: Core to any state-sharing discussion.

Common follow-up questions

  • Why can context cause performance problems?
  • Is context a replacement for Redux?

This is 1 of 118+ questions in the React Interview Kit

Get every question with detailed answers, follow-ups and real code — plus coding challenges and a last-minute revision sheet. One-time payment, instant access.

⚡ Get the React Interview Kit → ₹399

Full kit

React Interview Kit · ₹399

Get it →