⚛️ 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

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

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

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

jsx

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

jsx

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

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

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

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

jsx

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

jsx

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

jsx

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

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

jsx

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

jsx

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

jsx

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

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

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

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

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

jsx

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