⚛️ React Interview Questions

Master React interviews with questions on hooks, components, state management, and performance optimization

Virtual DOM, JSX, components, props, state, events, and React fundamentals

15-Minute React Cheatsheet

Quick reference for last-minute interview preparation

⚛️ Core Concepts

Virtual DOM: Lightweight copy for efficient updates
JSX: JavaScript + XML syntax extension
Components: Reusable UI building blocks
Props: Read-only data passed to components
State: Mutable data managed by component

🪝 Essential Hooks

useState - Local state management
useEffect - Side effects & lifecycle
useContext - Access context values
useRef - Mutable refs, DOM access
useMemo/useCallback - Memoization

🚀 Performance

React.memo - Prevent unnecessary re-renders
useMemo - Cache expensive calculations
useCallback - Stable function references
lazy/Suspense - Code splitting
Keys: Stable, unique identifiers for lists

✨ React 18+ Features

Concurrent Rendering: Non-blocking updates
useTransition - Mark non-urgent updates
useDeferredValue - Defer re-renders
Automatic Batching: Groups state updates
Server Components: RSC for zero-JS components

📦 State Management

useState: Simple local state
useReducer: Complex state logic
Context API: Prop drilling solution
Redux: Global state, middleware support
Zustand/Jotai: Lightweight alternatives

🏗️ Component Patterns

Container/Presentational: Logic vs UI separation
Compound Components: Flexible, related components
Render Props: Share code via prop function
Custom Hooks: Reusable stateful logic
HOC: Component enhancement wrapper

⚠️ Common Interview Gotchas

• State updates are asynchronous and batched
• useEffect cleanup runs before next effect
• Don't call hooks inside loops or conditions
• Keys should be stable, not array indices
• useCallback/useMemo need correct dependencies
• Context causes all consumers to re-render

What is the Virtual DOM and how does React use it?

Easy

The Virtual DOM is a lightweight JavaScript representation of the actual DOM. React uses it to optimize rendering performance through a process called "reconciliation."

  • Virtual DOM Creation: React creates a virtual representation of the UI in memory
  • Diffing: When state changes, React creates a new virtual DOM and compares it with the previous one
  • Reconciliation: Only the differences are applied to the real DOM
  • Batching: Multiple updates are batched together for efficiency
jsx

Explain the difference between useState and useReducer hooks

Medium

Both hooks manage state, but useReducer is preferable for complex state logic involving multiple sub-values or when the next state depends on the previous one.

jsx

What is the useEffect hook and explain its cleanup function?

Medium

useEffect handles side effects in functional components. The cleanup function runs before the component unmounts and before each re-run of the effect.

jsx

How do useMemo and useCallback work? When should you use them?

Medium

useMemo caches computed values, while useCallback caches function references. Both prevent unnecessary recalculations and re-renders.

jsx

What is React Context API and when should you use it?

Medium

Context API provides a way to pass data through the component tree without manually passing props at every level. It solves the "prop drilling" problem.

jsx

Explain React's reconciliation algorithm and keys

Hard

Reconciliation is React's algorithm for diffing two trees and determining which parts need to be updated. Keys help React identify which items have changed, been added, or removed.

jsx

What are React Server Components and how do they differ from Client Components?

Hard

React Server Components (RSC) render on the server with zero JavaScript sent to the client. They can directly access backend resources and reduce bundle size.

jsx

How do you handle forms in React? Controlled vs Uncontrolled components

Medium

Controlled components store form data in React state.Uncontrolled components let the DOM handle form data, accessed via refs.

jsx

What are Custom Hooks and how do you create them?

Medium

Custom Hooks are reusable functions that encapsulate stateful logic. They must start with "use" and can call other hooks.

jsx

What is React.memo and when should you use it?

Medium

React.memo is a higher-order component that memoizes the rendered output, preventing unnecessary re-renders when props haven't changed.

jsx

Explain the useRef hook and its use cases

Easy

useRef returns a mutable ref object that persists across renders. It's commonly used for DOM access and storing mutable values without causing re-renders.

jsx

What is React Suspense and how do you implement code splitting?

Hard

Suspense lets components "wait" for something before rendering. Combined withReact.lazy, it enables code splitting to reduce initial bundle size.

jsx

What are React 18's concurrent features (useTransition, useDeferredValue)?

Hard

React 18 introduced concurrent rendering, allowing React to prepare multiple versions of the UI at the same time without blocking the main thread.

jsx

How does React handle events (Synthetic Events)?

Easy

React uses SyntheticEvent, a cross-browser wrapper around the browser's native event. Events are delegated to the root element for performance.

jsx

Explain React Error Boundaries and error handling strategies

Medium

Error Boundaries are React components that catch JavaScript errors in their child component tree, log errors, and display a fallback UI. They must be class components.

jsx

What is prop drilling and how do you avoid it?

Medium

Prop drilling is passing props through multiple component levels to reach a deeply nested component. It can be avoided using Context API, state management libraries, or component composition.

jsx

What is the difference between class components and functional components?

Easy

Class components use ES6 classes with lifecycle methods, while functional components are simpler functions that use hooks for state and side effects. Functional components are now preferred.

jsx

How do you implement infinite scrolling in React?

Medium

Infinite scrolling loads more content as the user scrolls. It can be implemented using Intersection Observer API, scroll events, or libraries like react-infinite-scroll.

jsx

How do you optimize React application performance?

Hard

React performance optimization involves reducing unnecessary re-renders, code splitting, memoization, and efficient state management.

jsx

What are Higher-Order Components (HOC) and render props patterns?

Hard

HOCs and render props are patterns for sharing logic between components. While still valid, custom hooks have largely replaced these patterns in modern React.

jsx

Interview Tips for React