PGoCareerGoCareer prep tools
Home
LoginSign up
  • Java
  • Python
  • AI
  • React
  • Angular
  • PHP
  • Node.js
  • SQL
  • DSA
  • HTML
  • CSS
  • JS
  • Spring
  • ML
  • MongoDB

React · Theory

Context in React

← All stacks

Theory

35/94

Context in React

Context skips prop drilling. createContext, wrap a tree in Provider value={…}, read with useContext in a child. Theme, current user, locale are classic. Don’t put fast-changing data (every keystroke of a form) in Context at the root — every consumer re-renders.

If only one child needs the value, pass a prop. Context is for ‘many deep children, rarely changes’ or ‘truly global concerns’.

Context in React — on screen — dark. Label did not get a theme prop. Provider sat above it.

Diagram
Provider value
      │
      ▼
  deep child
   useContext
Exam tip

When to use vs a prop. Re-render warning.

Example

// Context
import { createContext, useContext } from "react";

const Theme = createContext("light");

function Label() {
  const theme = useContext(Theme);
  return <span>{theme}</span>;
}

export default function App() {
  return (
    <Theme.Provider value="dark">
      <Label />
    </Theme.Provider>
  );
}

Context in React — on screen: dark. Label did not get a theme prop. Provider sat above it.

Short notes

  • DefProvider + useContext.
  • Usetheme / auth / locale.
  • Trapall app state in one context.

Questions

1

When is Context overkill?

Previous← Code Splitting in ReactNextReact Hooks →
P

GoCareerGo

Utilities · Preparation Hub · Resume · CV · Tools — one workspace.

Workspace

DashboardProfilePreparation HubResume builderCV builderCareer planning

PDF Tools

Merge PDFSplit PDFCompress PDFImage to PDFAll toolsJobs

Image & QR

Compress ImageResize ImageQR ScannerQR GeneratorBlogIT interview prep

Company

FAQFeedbackContactPrivacyTermsSitemap

© 2026 GoCareerGo. Keep moving forward.