⚛️ 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
🪝 Essential Hooks
useState - Local state managementuseEffect - Side effects & lifecycleuseContext - Access context valuesuseRef - Mutable refs, DOM accessuseMemo/useCallback - Memoization🚀 Performance
React.memo - Prevent unnecessary re-rendersuseMemo - Cache expensive calculationsuseCallback - Stable function referenceslazy/Suspense - Code splitting✨ React 18+ Features
useTransition - Mark non-urgent updatesuseDeferredValue - Defer re-renders📦 State Management
🏗️ Component Patterns
⚠️ Common Interview Gotchas
What is the Virtual DOM and how does React use it?
EasyThe 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
Explain the difference between useState and useReducer hooks
MediumBoth 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.
What is the useEffect hook and explain its cleanup function?
MediumuseEffect handles side effects in functional components. The cleanup function runs before the component unmounts and before each re-run of the effect.
How do useMemo and useCallback work? When should you use them?
MediumuseMemo caches computed values, while useCallback caches function references. Both prevent unnecessary recalculations and re-renders.
What is React Context API and when should you use it?
MediumContext API provides a way to pass data through the component tree without manually passing props at every level. It solves the "prop drilling" problem.
Explain React's reconciliation algorithm and keys
HardReconciliation 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.
What are React Server Components and how do they differ from Client Components?
HardReact Server Components (RSC) render on the server with zero JavaScript sent to the client. They can directly access backend resources and reduce bundle size.
How do you handle forms in React? Controlled vs Uncontrolled components
MediumControlled components store form data in React state.Uncontrolled components let the DOM handle form data, accessed via refs.
What are Custom Hooks and how do you create them?
MediumCustom Hooks are reusable functions that encapsulate stateful logic. They must start with "use" and can call other hooks.
What is React.memo and when should you use it?
MediumReact.memo is a higher-order component that memoizes the rendered output, preventing unnecessary re-renders when props haven't changed.
Explain the useRef hook and its use cases
EasyuseRef returns a mutable ref object that persists across renders. It's commonly used for DOM access and storing mutable values without causing re-renders.
What is React Suspense and how do you implement code splitting?
HardSuspense lets components "wait" for something before rendering. Combined withReact.lazy, it enables code splitting to reduce initial bundle size.
What are React 18's concurrent features (useTransition, useDeferredValue)?
HardReact 18 introduced concurrent rendering, allowing React to prepare multiple versions of the UI at the same time without blocking the main thread.
How does React handle events (Synthetic Events)?
EasyReact uses SyntheticEvent, a cross-browser wrapper around the browser's native event. Events are delegated to the root element for performance.
Explain React Error Boundaries and error handling strategies
MediumError 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.
What is prop drilling and how do you avoid it?
MediumProp 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.
What is the difference between class components and functional components?
EasyClass 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.
How do you implement infinite scrolling in React?
MediumInfinite scrolling loads more content as the user scrolls. It can be implemented using Intersection Observer API, scroll events, or libraries like react-infinite-scroll.
How do you optimize React application performance?
HardReact performance optimization involves reducing unnecessary re-renders, code splitting, memoization, and efficient state management.
What are Higher-Order Components (HOC) and render props patterns?
HardHOCs and render props are patterns for sharing logic between components. While still valid, custom hooks have largely replaced these patterns in modern React.
Interview Tips for React
- ✓ Understand the Virtual DOM and reconciliation process
- ✓ Master hooks: useState, useEffect, useMemo, useCallback, useRef
- ✓ Know when to use Context API vs state management libraries
- ✓ Be familiar with React 18+ features (Concurrent, Suspense, Server Components)
- ✓ Understand performance optimization techniques
- ✓ Practice building custom hooks for reusable logic
- ✓ Know the difference between controlled and uncontrolled components
- ✓ Be ready to discuss component patterns and best practices