Medium15 minReact Fundamentals
UpdatedAug 1, 2026
Edit

React State Management

Question Variations

  • "When should you use React Context instead of a dedicated state management library like Redux or Zustand?"
  • "What are the performance implications of using React Context for frequently updated state?"
  • "How does Zustand solve the 'prop drilling' problem differently than Redux?"
  • "What is the difference between 'local state' and 'global state,' and how do you decide where a piece of state belongs?"

Why This Is Asked

State management choices have a direct impact on application performance and maintainability. Interviewers want to see that you understand the re-render implications of Context, know when to reach for external libraries, and can articulate the trade-offs.

Key Concepts

  • Context API: built-in, zero dependencies, ideal for low-frequency data (theme, auth, locale)
  • Context triggers re-renders for all consumers when the provider value changes — no selector support
  • State libraries (Zustand, Redux): use subscription models with selectors to prevent unnecessary re-renders
  • Zustand/Jotai are minimal-boilerplate alternatives to Redux for most use cases
  • The decision depends on update frequency, state complexity, and whether you need middleware/devtools

Question Variations

  • “When should you use React Context instead of a dedicated state management library like Redux or Zustand?”
  • “What are the performance implications of using React Context for frequently updated state?”
  • “How does Zustand solve the ‘prop drilling’ problem differently than Redux?”
  • “What is the difference between ‘local state’ and ‘global state,’ and how do you decide where a piece of state belongs?”

Answers by Technology

+ Add Variant
ReactImprove this answer ✏️

Expected Answer

The choice between Context API and a Global State Library (like Zustand or Redux) depends on the frequency of updates and the complexity of the data:

  • Context API: Best for “static” or low-frequency data (Themes, User Auth, Locale). It is built-in but lacks a “selector” mechanism, meaning every component consuming the context re-renders whenever any part of the context value changes.
  • State Libraries: Best for high-frequency or complex global state. They use a subscription/selector model to ensure that a component only re-renders when the specific slice of data it cares about changes.

Why It Matters

Using Context API for high-frequency state (like an input field or a real-time price ticker) can lead to performance bottlenecks. Since Context triggers re-renders for all consumers, a single keystroke in a large application could trigger hundreds of unnecessary renders, making the UI feel sluggish. Libraries like Zustand solve this by decoupling state updates from the React render tree.

Example Code

Context API (Triggers re-render for all consumers)

const UserContext = createContext();

function Profile() {
  const { name } = useContext(UserContext); // Re-renders if name OR email changes
  return <div>{name}</div>;
}

Zustand (Selector-based, efficient)

const useStore = create((set) => ({
  name: "Frog",
  email: "frog@example.com",
}));

function Profile() {
  const name = useStore(state => state.name); // ONLY re-renders if name changes
  return <div>{name}</div>;
}

Common Mistakes

  • Using Context for “Prop Drilling” only: Context is a dependency injection tool, not just a way to avoid passing props. If the data is only used by a small sub-tree, consider passing props or using component composition instead.
  • One Giant Context: Putting the entire application state into a single Context Provider. This guarantees that a change to one tiny piece of state will re-render the entire application.

Follow-up Questions

  • How can you optimize Context performance without a library? (Answer: Split one large context into several smaller, focused contexts; or wrap child components in React.memo).
  • Why is Zustand often preferred over Redux? (Answer: Less boilerplate, no need to wrap the app in a Provider, and a simpler hook-based API).

References