JavaScriptReactAngularVueSvelteCSSHTMLTypeScript

React Interview Questions

140+ most important React interview questions on component architecture, hooks, state management, performance, and real-world UI components.
Questions and solutions by ex-interviewers
Test scenarios
Code in browser

Questions List

React Interview PlaybookA comprehensive React interview guide that covers core concepts and interview-specific React tips
0/12 guides
GUIDES
  • What is React? Describe the benefits of ReactReact is an open-source library maintained by Meta and the community for building user interfaces from components. Components describe UI declaratively from…
    Topics
    React
  • What is the difference between React Node, React Element, and a React Component?A React Node is a value React can render, including an element, string, number, bigint, iterable of nodes, portal, or an empty value such as null or a boolean…
    Topics
    React
  • What is JSX and how does it work?JSX is a syntax extension for JavaScript that lets you describe UI with HTML-like markup inside JavaScript. A build tool transforms it into ordinary function…
    Topics
    React
  • What is the difference between state and props in React?State is data a component owns and can update over time; props are data a component receives from its parent and must treat as read-only. A state update…
    Topics
    React
  • What is the purpose of the `key` prop in React?The key prop tells React how to identify each child in a list across renders so it can match the right component instance to the right data, preserve its…
    Topics
    React
  • What is the consequence of using array indices as the value for `key`s in React?Using array indices as keys causes React to reconcile the list incorrectly when items are reordered, inserted, or removed. Because the key identifies a…
    Topics
    React
  • What is the difference between controlled and uncontrolled React components?A controlled component drives a form input from React state; you pass value/checked plus an onChange handler, and React state is the single source of truth. An…
    Topics
    React
  • What are some pitfalls about using context in React?Context in React is convenient but easy to misuse. The biggest pitfalls are passing a fresh object or array as the provider value on every render, assuming…
    Topics
    React
  • What are the benefits of using hooks in React?Hooks let function components use state, context, refs, effects, and other React features without classes. Custom Hooks compose reusable stateful logic without…
    Topics
    React
  • What are the rules of React hooks?React hooks have a few essential rules to ensure they work correctly. Call hooks at the top level of a function component or custom hook, never inside loops…
    Topics
    React
  • What is the difference between `useEffect` and `useLayoutEffect` in React?Both hooks run side effects after render, but they differ in when they fire relative to paint: useEffect runs after React commits. For effects not caused by an…
    Topics
    React
  • What is the purpose of callback function argument format of `setState()` in React and when should it be used?The callback (or updater function) form of setState (both this.setState(prev => ...) in classes and setX(prev => ...) with useState) guarantees that each…
    Topics
    React
  • What does the dependency array of `useEffect` affect?The dependency array of useEffect controls when React re-synchronizes the effect. With no array, React runs setup after every commit. With [], it runs setup…
    Topics
    React
  • What is the `useRef` hook in React and when should it be used?The useRef hook in React is used to create a mutable object that persists across renders. It can be used to access and manipulate DOM elements directly, store…
    Topics
    React
  • What is the `useCallback` hook in React and when should it be used?useCallback caches a function definition while its dependencies remain Object.is-equal. The point is referential stability, so a memo-wrapped child can skip a…
    Topics
    React
  • What is the `useMemo` hook in React and when should it be used?useMemo caches a calculation result between renders while its dependencies remain Object.is-equal. Use it as a performance optimization for a measured…
    Topics
    React
  • What is the `useReducer` hook in React and when should it be used?The useReducer hook in React is used for managing complex state logic in functional components. It is an alternative to useState and is particularly useful…
    Topics
    React
  • What is the `useId` hook in React and when should it be used?useId (added in React 18) generates a stable, unique string ID per component instance, per React root. Its main reason for existing is to produce IDs that…
    Topics
    React
  • What does re-rendering mean in React?A re-render means React calls a function component again (or calls a class component's render) to compute a new element description. State updates, context…
    Topics
    React
  • What are React Fragments used for?React Fragments are used to group multiple elements without adding extra nodes to the DOM. This is useful when you want to return multiple elements from a…
    Topics
    React
  • What is `forwardRef()` in React used for?As of React 19 (December 2024), forwardRef() is no longer necessary, function components can now accept ref as a regular prop, so wrapping in forwardRef() is…
    Topics
    React
  • How do you reset a component's state in React?The most idiomatic way to reset a component's state in React is to give the component a key prop and change it: React unmounts the old instance and mounts a…
    Topics
    React
  • Why does React recommend against mutating state?React treats state as a read-only snapshot. Mutating an object or array in place keeps the same reference, so an Object.is state bailout, memoized child…
    Topics
    React
  • What are error boundaries in React for?Error boundaries catch errors thrown while rendering their descendant tree and display fallback UI instead of losing the entire React root. They are class…
    Topics
    React
  • How do you test React applications?A common stack is Jest or Vitest as the test runner with React Testing Library, which encourages testing observable behavior instead of implementation details…
    Topics
    React
  • Explain what React hydration isHydration is the process in which React renders the client tree, matches it to HTML previously produced by React on the server, attaches event handling, and…
    Topics
    React
  • What are React Portals used for?React Portals are used to render children into a DOM node that exists outside the hierarchy of the parent component. This is useful for scenarios like modals…
    Topics
    React
  • How do you debug React applications?Use React Developer Tools to inspect the component tree and profile commits, browser breakpoints and network tools for runtime behavior, and development Strict…
    Topics
    React
  • What is React Strict Mode and what are its benefits?<StrictMode> enables development-only checks for a React subtree. React renders components an extra time to expose impure rendering, runs an extra…
    Topics
    React
  • How do you localize React applications?To localize a React application, you typically use a library like react-i18next or react-intl. First, you set up your translation files for different…
    Topics
    ReactInternationalization
  • What is code splitting in a React application?Code splitting in a React application is a technique used to improve performance by splitting the code into smaller chunks that can be loaded on demand. This…
    Topics
    React
  • How would you optimize the performance of React contexts to reduce rerenders?Context consumers re-render whenever the provider receives a different value according to Object.is. Neither memo nor React Compiler prevents that subscription…
    Topics
    ReactPerformance
  • What are higher-order components in React?Higher-order components (HOCs) in React are functions that take a component and return a new component with additional props or behavior. They are used to…
    Topics
    React
  • What is the Flux pattern and what are its benefits?Flux is a historical application architecture Facebook introduced for managing state around React. An action goes through a central dispatcher to registered…
    Topics
    React
  • Explain one-way data flow of React and its benefitsIn React, one-way data flow means that data moves from parent components to children through props and context. Children treat those inputs as read-only; to…
    Topics
    React
  • How do you handle asynchronous data loading in React applications?Prefer a framework's data-loading APIs when they can coordinate route requests before rendering, or a client cache such as TanStack Query, SWR, or RTK Query…
    Topics
    ReactAsync
  • Explain server-side rendering of React applications and its benefitsServer-side rendering (SSR) renders React output to HTML on the server and sends it to the browser. hydrateRoot then attaches React to matching client-rendered…
    Topics
    React
  • Explain static generation of React applications and its benefitsStatic generation (SSG) renders HTML ahead of requests, usually during a build, so the result can be cached and served from a CDN. React itself provides static…
    Topics
    React
  • Explain the presentational vs container component pattern in ReactThe presentational vs container component pattern (also known as "dumb vs smart components") splits components into two roles: presentational components decide…
    Topics
    React
  • What are some common pitfalls when doing data fetching in React?Common data-fetching pitfalls include missing loading and error states, ignoring HTTP error statuses, leaving stale requests active, allowing responses to win…
    Topics
    React
  • What are render props in React and what are they for?Render props in React are a technique for sharing code between components using a prop whose value is a function. The component calls that function with some…
    Topics
    React
  • What are some React anti-patterns?React anti-patterns are practices that lead to inefficient, buggy, or hard-to-maintain code. Common ones in modern (hooks-era) React include: Mutating state…
    Topics
    React
  • How do you decide between using React state, context, and external state managers?Match the tool to the kind of state. Use useState/useReducer for local component state, and lift state up before reaching for anything heavier. Context…
    Topics
    React
  • Explain the composition pattern in ReactThe composition pattern in React is the practice of building UIs by combining smaller, reusable components instead of extending them through inheritance. The…
    Topics
    React
  • What is virtual DOM in React?The "virtual DOM" in React is a tree of plain JavaScript objects (React elements) that describes what the UI should look like: it is not a copy of the actual…
    Topics
    React
  • How does virtual DOM in React work? What are its benefits and downsides?The "virtual DOM" is not a copy of the browser DOM. It is shorthand for the React element descriptions produced by components, together with React's internal…
    Topics
    React
  • What is React Fiber and how is it an improvement over the previous approach?Fiber is React's internal reconciliation architecture, introduced in React 16. A Fiber represents a unit of work and links to related Fibers in the component…
    Topics
    React
  • What is reconciliation in React?Reconciliation is React's render-phase process for matching a newly returned element tree with the previous tree. Element types, positions, and keys determine…
    Topics
    React
  • What is React Suspense and what does it enable?Suspense lets React display a fallback while a descendant is not ready to render. Supported sources include code loaded with lazy, cached promises read with…
    Topics
    React
  • Explain what happens when the `useState` setter function is called in ReactCalling a useState setter queues either a replacement value or an updater function for the component's next render. It does not change the state variable in…
    Topics
    React

React Quiz Interview Questions and Answers

React interviews often include a mix of technical trivia and problem-solving challenges designed to assess your understanding of the framework. These trivia-style questions aim to gauge your knowledge of React fundamentals, its core concepts, and how well you grasp advanced features. If you're preparing for a React interview, you're likely to encounter questions that cover a range of critical topics, from component lifecycle and state management to performance optimization, hooks, and testing.

This list of practice questions offers a curated collection of the top React quiz questions commonly asked in interviews. Each question is carefully chosen to highlight the essential areas you need to focus on and is paired with detailed answers crafted by experienced interviewers.

Why React Quiz Questions Are Critical in Interviews

Employers use trivia questions in React interviews for several reasons. These questions provide insight into a candidate's depth of knowledge, their ability to think on their feet, and how well they've mastered the nuances of React. While solving coding challenges showcases problem-solving skills, trivia-style questions often reveal how familiar you are with the framework's core concepts and best practices.

In real-world scenarios, understanding React goes beyond just writing components. It's about creating efficient, reusable, and performant applications. Interviewers often ask questions in areas such as:

  • Component Lifecycle: Understanding how components mount, update, and unmount is essential for managing UI and state.
  • State and Props Management: Knowing when and how to use props, state, and context to share data across components.
  • Hooks: Leveraging React hooks like useState, useEffect, and useReducer to simplify logic and manage side effects.
  • Performance: Optimizing rendering, using memoization, and handling large datasets efficiently.
  • Testing: Writing robust tests for React components using tools like Jest and React Testing Library.
  • Routing: Navigating and managing views in single-page applications with React Router.

Being well-versed in these areas not only boosts your chances of clearing the interview but also prepares you for tackling real-world challenges you will face on the job.

Example React Quiz Questions

Here are some examples of the types of questions you might face in a React interview, categorized by topic.

1. Component Lifecycle

  • Question: What is the difference between componentDidMount and componentDidUpdate?
    • Answer: componentDidMount is invoked once after the component is inserted into the DOM, often used for API calls or subscriptions. componentDidUpdate is called after updates to props or state, useful for actions requiring updated DOM data.
  • Question: How can you handle cleanup in React components?
    • Answer: Cleanup is handled in the componentWillUnmount method for class components or inside the cleanup function returned by useEffect for functional components.

2. State and Props Management

  • Question: What is the difference between state and props?
    • Answer: State is a local data store owned by a component and can change over time. Props are immutable data passed from a parent to a child component to configure or control the child.
  • Question: How do you manage global state in a React application?
    • Answer: Global state can be managed using Context API, Redux, or third-party libraries like Zustand or MobX.

3. Hooks

  • Question: How does the useEffect hook differ from lifecycle methods?
    • Answer: useEffect can replace componentDidMount, componentDidUpdate, and componentWillUnmount in functional components. It allows combining setup and cleanup logic in one place.
  • Question: What are custom hooks, and when should you use them?
    • Answer: Custom hooks encapsulate reusable logic that involves state or side effects, making code more modular and DRY (Don't Repeat Yourself).

4. Performance

  • Question: How can you prevent unnecessary re-renders in React?
    • Answer: Use React.memo for functional components, PureComponent for class components, or hooks like useMemo and useCallback to memoize values and functions.
  • Question: What is React's reconciliation process?
    • Answer: Reconciliation is React's process of updating the DOM efficiently by comparing the virtual DOM with the previous version and applying minimal updates.

5. Testing

  • Question: What is the difference between shallow rendering and full rendering in testing?
    • Answer: Shallow rendering tests a component in isolation without rendering child components, while full rendering (e.g., using mount in Enzyme) renders the entire component tree.
  • Question: How can you test React hooks?
    • Answer: Use libraries like React Testing Library and tools like renderHook from @testing-library/react-hooks to test custom hooks directly.

6. Routing

  • Question: How do you handle navigation in a React single-page application?
    • Answer: Use React Router to define routes and manage navigation with components like <BrowserRouter>, <Route>, and <Link>.
  • Question: How can you implement route-based code splitting in React?

Answer: Use React.lazy and Suspense to dynamically load components for specific routes:

const LazyComponent = React.lazy(() => import('./LazyComponent'));
<Suspense fallback={<div>Loading...</div>}>
<LazyComponent />
</Suspense>;

How These Questions Help You Prepare

This guide is designed to do more than just familiarize you with common React interview questions; it provides the tools you need to confidently approach any technical discussion. By reviewing these examples, you will:

  1. Improve React fundamentals: Develop a stronger foundation in both React basics and advanced topics by learning how to answer questions that often appear in real interviews.
  2. Enhance problem-solving: Practice connecting theoretical concepts to real-world applications, making it easier to demonstrate your skills to interviewers.
  3. Build confidence: Rehearse concise and well-structured answers, so you're ready to communicate effectively under pressure.

To make the learning process more effective, each question is paired with:

  • Quick answers (TL;DR): Short and precise responses for interviews when time is limited.
  • Comprehensive explanations: Detailed answers providing full context and examples to ensure you understand the topic deeply.

This dual-answer format equips you with flexibility, allowing you to adapt your response to the interview's flow and depth of questioning. By focusing on practical, real-world knowledge, these questions also ensure you're well-prepared to solve problems and write efficient, maintainable React code, which are skills that matter in actual job scenarios.

Why Our Answers Stand Out

The answers provided in this guide are written by experienced ex-interviewers who have conducted hundreds of React interviews. These experts understand what employers look for in candidates and how to craft answers that stand out. Each response is tailored to highlight your knowledge and problem-solving approach, ensuring you make a strong impression.

By studying these questions and answers, you're not only preparing for an interview but also enhancing your overall React expertise. Whether you're a beginner or an experienced developer, this comprehensive guide can help you improve your skills and build confidence for your next interview.

Related lists

Check out other lists of questions below if you're looking for something more specific: