D
DevPrepSystematic Prep
DEVPREP CODEX · #02

Context API Interview Questions

60 curated questions graded from Foundations (Easy) to Practical Patterns (Medium) and Internals & Architecture (Hard).

TOTAL QUESTIONS

60

THEORY QUESTIONS

60

IMPLEMENTATION FOLIOS

0

FREE QUESTIONS

5 / Level

Easy Level·20 Questions Total

Foundations & Core Concepts

Open Full Easy List
Q1What is the Context API and what problem does it solve?
  • React's built-in mechanism for passing data through the component tree without threading props through every intermediate layer ("prop drilling").
  • A Provider supplies a value; any descendant consumer reads it regardless of depth.
  • Solves: theming, locale, authenticated-user identity, feature flags — low-frequency globals needed by distant leaves.
  • Not a state manager by itself: it distributes values; change logic still lives in useState/useReducer above it.

Q2How do you create and consume a context?
const ThemeContext = createContext('light');          // default value
<ThemeContext.Provider value="dark">
  <Toolbar />                                          // reads 'dark'
</ThemeContext.Provider>

Consumer (modern):

const theme = useContext(ThemeContext);

Legacy <ThemeContext.Consumer>{v => ...}</ThemeContext.Consumer> still exists but hooks replaced it. The default value only applies when NO provider exists above — useful for testing and optional contexts.


Q3When should you reach for Context versus props?
  • Props: data consumed by few, nearby components; explicitness aids tracing.
  • Context: same value needed by MANY distant components; identity-style data (theme/user/locale) changing rarely. Litmus tests:
  1. Would drilling pass through ≥3 unrelated layers? → consider context.
  2. Does the value change on every keystroke? → probably belongs local or in an external store instead. Overusing context for everything recreates hidden global coupling — the problem libraries like Redux were born from.

Q4What causes unnecessary re-renders with Context and how do you mitigate?
  • Every consumer re-renders whenever the Provider's value changes — reference changes matter, not deep content.
  • Typical footgun: value={{user, setUser}} inline object → new identity every render of provider parent → ALL consumers re-render constantly. Mitigations:
  1. useMemo the provided object.
  2. Split contexts by change frequency (stable auth vs hot filters).
  3. Push state down to the smallest common subtree.
  4. For high-frequency shared state, graduate to external stores with selector subscriptions.

Q5What is the recommended pattern of splitting contexts?
  • Separate READ context from UPDATE (dispatch) context:
<UserCtx.Provider value={state}>
 <UserDispatchCtx.Provider value={dispatch}>...

Components needing only actions subscribe to a stable dispatch and skip re-renders caused by state changes.

  • Also split by domain (ThemeCtx/AuthCtx) rather than one mega-context — narrower blast radius per change. Interview phrasing: "context granularity is render-performance engineering."

15 More Easy Questions Locked

Unlock the complete Context API Easy question bank

Get instant access to all 20 questions, in-depth model answers, code sandboxes, and all 27+ technologies for a single one-time payment.

Unlock All — One-time payment · Lifetime access
DEDICATED LEVEL PAGES

Browse All Context API Questions by Difficulty

INTERNAL LINKING & DEPENDENCIES

Related Technologies to Context API

CAREER PATHWAYS

Context API is a key requirement for these engineering roles:

Context API Interview Questions — Easy, Medium & Hard | DevPrep | DevPrep