Web Development

Top 20 React.js Interview Questions and Answers (2026)

React.js is one of the most popular JavaScript libraries for building modern, interactive user interfaces. It is widely used in single-page applications,…

D
DevByteTechnical Author
Published
16 min read5 views
Top 20 React.js Interview Questions and Answers (2026)

React.js is one of the most popular JavaScript libraries for building modern, interactive user interfaces. It is widely used in single-page applications, dashboards, e-commerce websites, and full-stack applications.

If you are preparing for a React.js developer interview in 2026, understanding React fundamentals, hooks, state management, rendering, and performance optimization is essential.

In this guide, we will cover the top 20 React.js interview questions and answers, along with simple explanations and practical code examples to help you prepare for technical interviews.

1. What Is React.js?

Interview Answer:

React.js is an open-source JavaScript library developed by Meta for building user interfaces. It uses a component-based architecture, allowing developers to create reusable UI components. React also supports declarative rendering and provides hooks for managing state and component behavior.

Explanation:

React allows you to divide a user interface into smaller, reusable components.

For example, an e-commerce website might contain components such as:

  • Navbar

  • ProductCard

  • ProductList

  • ShoppingCart

  • Footer

Each component can be developed and maintained independently.

Example:

function Welcome() {
  return <h1>Welcome to React!</h1>;
}

export default Welcome;

Here, Welcome is a functional component that returns a heading.

Key points to remember:

  • React is a library, not a complete framework.

  • It uses components to build user interfaces.

  • It supports declarative UI development.

  • It can be used for web and native applications through different React-based tools.

2. What Is JSX in React?

Interview Answer:

JSX stands for JavaScript XML. It is a syntax extension for JavaScript that allows developers to write HTML-like markup inside JavaScript code. JSX is transformed into JavaScript instructions that React uses to create and update the UI.

Explanation:

Instead of manually creating elements using JavaScript functions, JSX makes UI code easier to read and maintain.

Example:

function App() {
  const name = "Manjeet";

  return <h1>Hello, {name}!</h1>;
}

export default App;

Output:

Hello, Manjeet!

Important JSX rules:

  • Return a single parent element, or use a fragment.

  • Use className instead of class.

  • Use curly braces {} to insert JavaScript expressions.

  • Close tags such as <img /> and <input />.

Example using a fragment:

function App() {
  return (
    <>
      <h1>Welcome</h1>
      <p>Learn React step by step.</p>
    </>
  );
}

3. What Are Components in React?

Interview Answer:

Components are independent, reusable building blocks of a React application. They allow developers to split a user interface into smaller parts that can manage their own logic and rendering.

React supports function components and class components, although function components with hooks are the standard choice in modern React development.

Explanation:

Consider a website with a navigation bar, sidebar, and product list. Each section can be implemented as a separate component.

Example:

function Navbar() {
  return <nav>My Website</nav>;
}

function Home() {
  return (
    <div>
      <Navbar />
      <h1>Welcome Home</h1>
    </div>
  );
}

export default Home;

Here, the Navbar component is reused inside the Home component.

Benefits of components:

  • Code reusability

  • Easier maintenance

  • Better organization

  • Improved testability

4. What Is the Difference Between Props and State?

Interview Answer:

Props and state are both used to manage data in React, but they serve different purposes. Props are passed from a parent component to a child component, while state is data managed by a component that can change over time.

Feature

Props

State

Purpose

Pass data between components

Manage changing component data

Controlled by

Parent component

Component or state owner

Direct modification

Should not be modified by the receiving component

Updated using the appropriate setter or update function

Changes trigger rendering

Yes, when they affect rendered output

Yes, when the updated state affects rendered output

Example

Product name passed to a card

Current quantity in a cart

Example using props:

function Greeting({ name }) {
  return <h1>Hello, {name}!</h1>;
}

function App() {
  return <Greeting name="Manjeet" />;
}

Example using state:

import { useState } from "react";

function Counter() {
  const [count, setCount] = useState(0);

  return (
    <button onClick={() => setCount(count + 1)}>
      Count: {count}
    </button>
  );
}

In the first example, name is passed through props. In the second, count is managed using state.

5. What Is the Virtual DOM in React?

Interview Answer:

The Virtual DOM is an in-memory representation of the UI that React uses to determine what changes are needed when the application updates. React compares the new render output with the previous one and commits the necessary changes to the actual DOM.

Explanation:

Suppose a page displays 100 products, and a user adds one item to the cart. React can update the relevant UI instead of requiring you to manually rebuild the entire page.

The general process is:

  1. State or props change.

  2. React renders the component again to calculate the next UI.

  3. React reconciles the new output with the previous output.

  4. React commits the necessary changes to the DOM.

Important: The Virtual DOM does not guarantee that every React update is faster than every manual DOM operation. Performance depends on the application and implementation.

6. What Are React Hooks?

Interview Answer:

React Hooks are functions that allow function components to use React features such as state, context, refs, and effects. Hooks were introduced in React 16.8.

Common hooks include:

  • useState

  • useEffect

  • useContext

  • useRef

  • useMemo

  • useCallback

  • useReducer

Example:

import { useState } from "react";

function Toggle() {
  const [isOn, setIsOn] = useState(false);

  return (
    <button onClick={() => setIsOn((previous) => !previous)}>
      {isOn ? "ON" : "OFF"}
    </button>
  );
}

Important rules of Hooks:

  1. Call Hooks at the top level of function components or custom Hooks.

  2. Do not call Hooks inside loops, conditions, or nested functions.

  3. Call Hooks only from React function components or custom Hooks.

These rules allow React to maintain the correct relationship between Hook calls and component state.

7. What Is the useState Hook?

Interview Answer:

useState is a React Hook that allows a function component to store and update state. It returns the current state value and a setter function.

Syntax:

const [state, setState] = useState(initialValue);

Example:

import { useState } from "react";

function Counter() {
  const [count, setCount] = useState(0);

  function increment() {
    setCount((previousCount) => previousCount + 1);
  }

  return (
    <div>
      <h2>{count}</h2>
      <button onClick={increment}>Increment</button>
    </div>
  );
}

Why use the functional updater?

When the next state depends on the previous state, use an updater function:

setCount((previousCount) => previousCount + 1);

This is especially useful when multiple updates are queued.

For example:

setCount((count) => count + 1);
setCount((count) => count + 1);
setCount((count) => count + 1);

These updates increment the count by three because each updater receives the result of the preceding updater.

8. What Is the useEffect Hook?

Interview Answer:

useEffect is a React Hook that allows a component to synchronize with external systems, such as browser APIs, subscriptions, timers, or network connections. It can also be used to fetch data when appropriate.

Example:

import { useEffect, useState } from "react";

function Users() {
  const [users, setUsers] = useState([]);

  useEffect(() => {
    let ignore = false;

    async function fetchUsers() {
      try {
        const response = await fetch(
          "https://jsonplaceholder.typicode.com/users"
        );

        if (!response.ok) {
          throw new Error("Failed to fetch users");
        }

        const data = await response.json();

        if (!ignore) {
          setUsers(data);
        }
      } catch (error) {
        if (!ignore) {
          console.error(error);
        }
      }
    }

    fetchUsers();

    return () => {
      ignore = true;
    };
  }, []);

  return (
    <ul>
      {users.map((user) => (
        <li key={user.id}>{user.name}</li>
      ))}
    </ul>
  );
}

Understanding the dependency array:

Dependency

Behavior

[]

Runs the effect's setup after the initial commit

[value]

Re-synchronizes when value changes

No dependency array

Re-synchronizes after every commit

The cleanup function runs before an effect is re-established and when the component is removed.

Important interview point: Effects are not needed for every calculation or event handler. If a value can be calculated directly from existing props or state, calculate it during rendering instead of storing a duplicate value through an effect.

9. What Is the Difference Between useEffect and useLayoutEffect?

Interview Answer:

Both hooks let you synchronize a component with external systems, but they differ in timing.

  • useEffect generally allows the browser to paint before running the effect when the update does not require blocking the paint.

  • useLayoutEffect runs after React updates the DOM but before the browser repaints. It is useful when an effect must measure or synchronously adjust layout before the user sees the result.

Example:

import { useLayoutEffect, useRef, useState } from "react";

function Box() {
  const boxRef = useRef(null);
  const [height, setHeight] = useState(0);

  useLayoutEffect(() => {
    if (boxRef.current) {
      setHeight(boxRef.current.getBoundingClientRect().height);
    }
  }, []);

  return (
    <div>
      <div ref={boxRef}>Measure this box</div>
      <p>Height: {height}px</p>
    </div>
  );
}

When should you use each?

Use useEffect for most external synchronization tasks. Use useLayoutEffect when you must measure layout or apply a visual adjustment before repainting.

Because useLayoutEffect can block painting, avoid using it unnecessarily.

10. What Is the Difference Between Controlled and Uncontrolled Components?

Interview Answer:

A controlled form component receives its current value from React state and updates that state through an event handler. An uncontrolled component stores its current value in the DOM, which can be accessed using a ref when needed.

Controlled component example:

import { useState } from "react";

function ControlledInput() {
  const [name, setName] = useState("");

  return (
    <input
      value={name}
      onChange={(event) => setName(event.target.value)}
      placeholder="Enter your name"
    />
  );
}

Uncontrolled component example:

import { useRef } from "react";

function UncontrolledInput() {
  const inputRef = useRef(null);

  function handleSubmit(event) {
    event.preventDefault();
    console.log(inputRef.current?.value);
  }

  return (
    <form onSubmit={handleSubmit}>
      <input ref={inputRef} defaultValue="" />
      <button type="submit">Submit</button>
    </form>
  );
}

Key difference: Controlled components make React state the source of truth for the input value. Uncontrolled components rely on the DOM to maintain the current value.

Controlled inputs are common when implementing validation, conditional forms, and live previews.

11. Why Are Keys Important in React?

Interview Answer:

Keys help React identify which items in a list have been added, removed, or reordered. They allow React to match list elements across renders.

Example:

function UserList({ users }) {
  return (
    <ul>
      {users.map((user) => (
        <li key={user.id}>{user.name}</li>
      ))}
    </ul>
  );
}

Here, user.id provides a stable key for each user.

Why avoid array indexes as keys?

Consider a list where users can be deleted or reordered. If array indexes are used as keys, React may associate an existing component with the wrong item, potentially causing unexpected UI or state behavior.

Prefer stable, unique identifiers from your data.

Can we use the same key in different lists?

Yes. Keys need to be unique among siblings in the same list, not across the entire application.

12. What Is React Context API?

Interview Answer:

The Context API allows a component to provide data to descendant components without passing props manually through every intermediate component.

It is useful for sharing data such as the current theme, locale, or authenticated user information.

Example:

import { createContext, useContext } from "react";

const ThemeContext = createContext("light");

function ThemeButton() {
  const theme = useContext(ThemeContext);

  return <button className={theme}>Current theme: {theme}</button>;
}

function App() {
  return (
    <ThemeContext.Provider value="dark">
      <ThemeButton />
    </ThemeContext.Provider>
  );
}

export default App;

Benefits:

  • Reduces prop drilling.

  • Makes shared data accessible to descendant components.

  • Works with custom Hooks and reusable providers.

Important: Context is not automatically the best choice for every state-management problem. Frequently changing context values can cause many consumers to re-render, so consider component structure and state ownership carefully.

13. What Is Prop Drilling in React?

Interview Answer:

Prop drilling is the process of passing data through multiple layers of components to reach a deeply nested component that needs it.

Example:

function App() {
  const user = { name: "Manjeet" };

  return <Parent user={user} />;
}

function Parent({ user }) {
  return <Child user={user} />;
}

function Child({ user }) {
  return <h2>Hello, {user.name}</h2>;
}

Here, Parent passes user to Child even though it does not use the data itself.

How can we avoid prop drilling?

  • Use the Context API for genuinely shared data.

  • Use a state-management library when application complexity justifies it.

  • Restructure components so data is passed only through components that need it.

  • Use component composition to pass elements or components directly.

Prop drilling is not always bad. Explicit props can make dependencies easier to understand in smaller applications.

14. What Is React.memo?

Interview Answer:

React.memo is a higher-order component that can skip re-rendering a function component when its props are unchanged according to its comparison function. By default, React compares each prop using Object.is.

Example:

import { memo, useState } from "react";

const UserProfile = memo(function UserProfile({ name }) {
  console.log("UserProfile rendered");

  return <h2>{name}</h2>;
});

function App() {
  const [count, setCount] = useState(0);

  return (
    <>
      <UserProfile name="Manjeet" />
      <button onClick={() => setCount((count) => count + 1)}>
        Count: {count}
      </button>
    </>
  );
}

When count changes, App re-renders, but UserProfile can skip rendering because its name prop remains unchanged.

Important points:

  • React.memo is a performance optimization, not a correctness guarantee.

  • It does not prevent re-renders caused by the component's own state or consumed context changing.

  • New object, array, or function references can prevent the default prop comparison from matching.

Use it when profiling indicates that avoiding a component's re-render is beneficial.

15. What Is the Difference Between useMemo and useCallback?

Interview Answer:

useMemo caches the result of a calculation between renders when its dependencies have not changed. useCallback caches a function definition between renders under the same condition.

Feature

useMemo

useCallback

Purpose

Cache a calculated value

Cache a function reference

Returns

The calculated value

The function

Common use

Expensive calculations

Stable callbacks passed to memoized children

Example

Filtered product list

Event handler

useMemo example:

import { useMemo, useState } from "react";

function ProductList({ products }) {
  const [search, setSearch] = useState("");

  const filteredProducts = useMemo(() => {
    return products.filter((product) =>
      product.name.toLowerCase().includes(search.toLowerCase())
    );
  }, [products, search]);

  return (
    <>
      <input
        value={search}
        onChange={(event) => setSearch(event.target.value)}
        placeholder="Search products"
      />

      {filteredProducts.map((product) => (
        <p key={product.id}>{product.name}</p>
      ))}
    </>
  );
}

useCallback example:

import { useCallback, useState } from "react";

function App() {
  const [count, setCount] = useState(0);

  const increment = useCallback(() => {
    setCount((previousCount) => previousCount + 1);
  }, []);

  return <button onClick={increment}>Count: {count}</button>;
}

Important: Neither hook should be added everywhere automatically. Use memoization when it provides a measurable benefit or when stable references are needed for an optimization.

16. What Is React Reconciliation?

Interview Answer:

Reconciliation is the process React uses to compare the previous rendered UI with the next rendered UI and determine what changes need to be committed.

React uses the element types, tree structure, and keys to determine whether existing component instances can be preserved or need to be replaced.

Example:

function App() {
  const [isAdmin, setIsAdmin] = useState(false);

  return (
    <div>
      <button onClick={() => setIsAdmin((value) => !value)}>
        Toggle Role
      </button>

      {isAdmin ? <h2>Admin Dashboard</h2> : <h2>User Dashboard</h2>}
    </div>
  );
}

When the state changes, React calculates the new UI and commits the necessary DOM updates.

Important interview points:

  • React does not blindly recreate the entire DOM after every state change.

  • Component type and position influence whether component state is preserved.

  • Keys help React match elements in lists.

  • Changing a component's identity can cause it to unmount and mount again, resetting its local state.

17. What Is the Difference Between Client-Side Rendering and Server-Side Rendering?

Interview Answer:

Client-side rendering (CSR) primarily uses JavaScript in the browser to render the application UI. Server-side rendering (SSR) generates HTML on the server for a request and sends it to the browser, after which React can hydrate the HTML to make it interactive.

Feature

CSR

SSR

Initial HTML

Often contains a basic app shell

Can contain rendered page content

Rendering work

Primarily browser-side

Server generates HTML, with client work when needed

Initial content display

May wait for JavaScript and data

Can display useful HTML earlier

SEO

Depends on crawler capabilities and implementation

Can make page content available in initial HTML

Server workload

Generally lower rendering workload

Requires server rendering work

Typical use

Client-heavy dashboards and apps

Content-rich pages and applications needing server-rendered HTML

Example:

A private analytics dashboard might use CSR, while a public blog could benefit from SSR or static generation.

Important: SSR does not automatically guarantee better performance or SEO. Caching, data-fetching strategy, HTML size, hydration cost, and deployment architecture all matter.

Frameworks such as Next.js provide multiple rendering strategies, including server rendering and static generation.

18. What Is Lazy Loading in React?

Interview Answer:

Lazy loading is a technique that delays loading a component or resource until it is needed. React provides lazy() for loading components dynamically and Suspense for displaying fallback UI while supported resources are loading.

Example:

import { lazy, Suspense } from "react";

const Dashboard = lazy(() => import("./Dashboard"));

function App() {
  return (
    <Suspense fallback={<p>Loading dashboard...</p>}>
      <Dashboard />
    </Suspense>
  );
}

export default App;

The Dashboard component is loaded through a dynamic import when React first needs to render it.

Benefits:

  • Reduces the amount of JavaScript loaded initially.

  • Can improve initial loading performance.

  • Supports route-based code splitting.

  • Helps large applications load features on demand.

Important: The bundler must support the dynamic import and split the code appropriately. A production application should also handle loading failures and provide a suitable error boundary where necessary.

19. How Do You Optimize Performance in React?

Interview Answer:

React performance can be improved by identifying unnecessary rendering, reducing JavaScript bundle size, avoiding expensive calculations, and loading only the code or data required by the user.

Common optimization techniques:

1. Use React.memo when appropriate

Prevent unnecessary re-renders of components whose props remain unchanged.

2. Use useMemo for expensive calculations

Cache calculated values when the dependencies have not changed.

3. Use useCallback when stable function references matter

This can help memoized child components avoid unnecessary re-renders.

4. Implement code splitting

Use dynamic imports and React.lazy to load components when needed.

5. Optimize lists

Use stable keys and consider list virtualization when rendering thousands of items.

6. Optimize images and assets

Use appropriately sized images, modern formats, and lazy loading for off-screen images.

7. Avoid unnecessary state

Do not duplicate values that can be calculated from existing props or state.

8. Use production builds

Development mode includes additional checks and behavior that can affect performance measurements.

9. Profile the application

Use React Developer Tools Profiler and browser performance tools to identify actual bottlenecks.

10. Consider server rendering or static generation

For suitable applications, server rendering and static generation can improve content availability and initial loading behavior.

Interview tip: Explain how you would measure performance before choosing an optimization. Unnecessary memoization can increase complexity without improving the user experience.

20. What Is the Difference Between useRef and useState?

Interview Answer:

useState stores information that participates in rendering. Updating state schedules a re-render when React processes the update. useRef stores a mutable value in an object whose identity remains stable across renders; changing its current property does not trigger a re-render.

Feature

useState

useRef

Stores values

Yes

Yes

Updating the value triggers a re-render

Yes, when React processes a meaningful state update

No

Common use

UI state

DOM references, timer IDs, mutable values

Value access

State variable

ref.current

useState example:

import { useState } from "react";

function Counter() {
  const [count, setCount] = useState(0);

  return (
    <button onClick={() => setCount((count) => count + 1)}>
      Count: {count}
    </button>
  );
}

useRef example:

import { useRef } from "react";

function SearchBox() {
  const inputRef = useRef(null);

  function focusInput() {
    inputRef.current?.focus();
  }

  return (
    <>
      <input ref={inputRef} placeholder="Search..." />
      <button onClick={focusInput}>Focus Input</button>
    </>
  );
}

Here, useRef provides access to the input DOM element so that it can receive focus.

When should you use each?

Use useState when a value affects what the UI should display. Use useRef for values that must persist between renders without triggering a re-render, or for accessing DOM elements.


Bonus: How Should You Prepare for a React.js Interview in 2026?

Knowing definitions is useful, but interviewers often want to understand how you apply React concepts to real applications.

Focus on these areas:

React Fundamentals

  • Components and JSX

  • Props and state

  • Conditional rendering

  • Lists and keys

  • Event handling

React Hooks

  • useState

  • useEffect

  • useContext

  • useRef

  • useMemo

  • useCallback

  • Custom Hooks

Advanced React Concepts

  • Reconciliation

  • Component identity and state preservation

  • Controlled and uncontrolled forms

  • Context API

  • Error boundaries

  • Lazy loading and Suspense

Performance Optimization

  • Avoiding unnecessary re-renders

  • Memoization

  • Code splitting

  • React Profiler

  • List virtualization

Practical Coding Exercises

Try building these projects to strengthen your interview preparation:

  1. Todo application with filtering.

  2. Searchable product listing with pagination.

  3. Form with validation.

  4. API-based user dashboard.

  5. Shopping cart with shared state.

  6. Debounced search component.

  7. Reusable modal component.

  8. Infinite scrolling list.

These projects help demonstrate your understanding of component design, state management, API integration, and performance optimization.

Conclusion

React.js interviews cover much more than JSX and components. A strong candidate understands how state updates work, how effects synchronize with external systems, how React identifies list items, and how to optimize applications without adding unnecessary complexity.

The 20 questions in this guide provide a solid foundation for beginner and intermediate React.js interviews in 2026.

My recommendation: Practice explaining each answer in your own words and write small code examples without looking at the documentation. This will help you perform better in interviews and become more confident when building real-world React applications.

D
DevByteAuthor

Technical author and software engineer at DevByte. Writing deep-dive tutorials on distributed systems, modern full-stack web architectures, and cloud deployments.

Keep Exploring

Related Engineering Dispatches

More guides and architectural patterns you might find valuable.

Browse All Articles↘