---
title: React Interview Questions and Answers (React 19.3)
url: https://www.masaischool.com/resources/react-interview-questions
description: 40 React interview questions with model answers: hooks, rendering, state, performance, Next.js, Server Components and coding problems, checked 11 Nov 2026.
updated: 2026-11-17
publisher: Masai (https://www.masaischool.com)
---

# React Interview Questions and Answers: 40 Model Answers Checked Against React 19.3

> **Short answer**
>
> React interviews test whether you understand components, state and Hooks, how React renders and updates the screen, and how to keep an app fast. As of 11 November 2026 the latest release is React 19.3. These 40 questions have short model answers, a version note for each newer feature and six coding problems.

These questions are for freshers and career switchers preparing for frontend and full-stack rounds in India, grouped by topic and answered for React 19.3. Facts were checked on 11 November 2026 against react.dev, the React release posts, the Next.js docs and the npm registry. **React 19** or **19.3** marks an answer that depends on a newer feature.

The JSX snippets were proofread, and Timer, Comment and useUser were also run once in jsdom with React 19.3.1. Masai's older [ReactJS interview questions and sample answers](https://www.masaischool.com/blog/reactjs-interview-questions-answers/) is a shorter list. For what to learn first, see the [frontend developer roadmap](https://www.masaischool.com/resources/frontend-developer-roadmap) and the [full stack developer roadmap](https://www.masaischool.com/resources/full-stack-developer-roadmap).

## Which React version to prepare for

| Release | Date | What it added |
|---|---|---|
| 16.3 | March 2018 | createContext, the current Context API |
| 16.6 | October 2018 | React.memo and React.lazy |
| 16.8 | February 2019 | Hooks, so function components can hold state |
| 17 | October 2020 | No new features; the new JSX transform |
| 18 | March 2022 | createRoot, automatic batching, Transitions, useId, useSyncExternalStore |
| 19 | December 2024 | Actions, useActionState, useOptimistic, use, ref as a prop, <Context> as a provider, stable Server Components |
| 19.2 | October 2025 | <Activity> and useEffectEvent |
| Compiler 1.0 | October 2025 | React Compiler, a separate build-time tool |
| 19.3 | September 2026 | <ViewTransition>, Fragment refs, use(browser()), Trusted Types |

Dates come from the react.dev versions page and release posts. npm's latest tag is 19.3.1, published 14 October 2026. The docs recommend a framework such as Next.js or React Router for new apps, and Create React App was deprecated for new apps on 14 February 2025.

## Core concepts, JSX and Hooks (Q1 to Q13)

### Core concepts and JSX

- **Q1. What is React, and why use it?** A JavaScript library for building interfaces from reusable components. You describe what the screen should look like for the current state, and React updates the DOM to match. Data flows one way, from parent to child.
- **Q2. What is JSX, and how does it differ from HTML?** JSX is syntax that a build tool compiles into JavaScript calls. Differences: one root or a Fragment, className and htmlFor, camelCase props like onClick, closed tags, expressions in braces. The new JSX transform removes import React from each file.
- **Q3. Function or class components?** Function components with Hooks. Classes still work, but react.dev says not to use them in new code. Error boundaries still need a class, as there is no function equivalent of getDerivedStateFromError yet. **React 19** dropped propTypes checks and function-component defaultProps.
- **Q4. Props versus state?** Props are read-only inputs from a parent. State is a component's own memory, changed through its setter, which re-renders it. When siblings share data, lift the state to their common parent and pass down the value and a callback.
- **Q5. Why does a list need a key, and why not the index?** Keys tell React which item is which between renders, so it can match and move them. Use a stable ID from your data. Indexes break when items are inserted or reordered, and Math.random() recreates every item.

### Hooks

- **Q6. What are the Rules of Hooks, and why?** Call Hooks only at the top level of a component or custom Hook, never in loops, conditions or after an early return. React matches Hooks to state by call order. Added in 16.8. **React 19:**use may be called conditionally.
- **Q7. How does useState work, and what are its traps?** State is a snapshot per render, so setCount(count + 1) called three times adds one. Use an updater, setCount(c => c + 1), when the next value depends on the last. Setters replace objects, not merge. React 18 batches updates everywhere.
- **Q8. What is useEffect for, and what do dependencies and cleanup do?** It syncs a component with an outside system, such as a timer, after commit. React re-runs it when a dependency changes, calling the old cleanup first. Do not use it to derive data or handle clicks. **React 19.2:**useEffectEvent reads fresh values without re-running it.
- **Q9. What is useRef, and when do you use it instead of state?** A ref keeps a value across renders without causing one, such as a DOM node or timer ID. Changing ref.current does not re-render, and you should not touch it during rendering. **React 19:** function components receive ref as a prop, and the docs mark forwardRef deprecated.
- **Q10. When are useMemo and useCallback worth it?** They cache a value or function until dependencies change. React calls this an optimisation, not a guarantee, so code must work without it. Use them for expensive calculations or props to memoised children. The compiler (Q21) can do this automatically.
- **Q11. useReducer or useState?**useReducer puts update logic in a pure function, (state, action) => newState. It suits related fields or many update types, and you can test it without rendering (Q38). Never mutate state in it: Strict Mode calls reducers twice in development to catch that.
- **Q12. How does Context work, and what is its cost?**createContext shares a value with descendants through useContext, avoiding prop drilling. Every consumer re-renders when the value changes, so keep it for slow-changing data like theme. **React 19:** render <ThemeContext value={x}> without .Provider; use(ThemeContext) works after an early return.
- **Q13. What is a custom Hook?** A function named useSomething that calls other Hooks to reuse stateful logic. Each call gets its own state, so you share logic, not state. Example: useUser(id) (Q40).

## Rendering, state and performance (Q14 to Q23)

### Rendering and reconciliation

- **Q14. What happens when state changes?** Three steps: trigger (the update queues a render), render (React calls your components to compute the new UI) and commit (React applies the smallest DOM changes, then runs effects). Rendering must be pure: same props, state and context, same output.
- **Q15. How does reconciliation work?** React compares the new tree with the old. The same component type at the same position keeps its state; a different type or key there is recreated. So changing a key resets a component, and you should never define a component inside another.
- **Q16. What does Strict Mode do?** In development only, it calls components, updaters and reducers twice, adds an extra effect setup and cleanup and re-runs ref callbacks, exposing impure code and missing cleanup. Production is unaffected, so a double log is not a bug. **19.3** also double-invokes effects during hydration.
- **Q17. What are Transitions and Suspense?** React 18 can pause and resume rendering. startTransition and useTransition mark an update non-urgent so typing stays responsive, useDeferredValue defers a value, and Suspense shows a fallback while something loads. **React 19:** transitions accept async functions, called Actions.

### State management

- **Q18. Where should state live?** Start local. Lift it to the nearest common parent when two components need it, use Context for rarely changing values, and use a store such as Redux Toolkit or Zustand when many distant components update shared state. Filters often belong in the URL.
- **Q19. What is server state, and why use TanStack Query?** Server state is data a backend owns, so it goes stale and needs caching, retries and refetching. TanStack Query handles that instead of hand-written effects with loading flags.

### Performance and newer features

- **Q20. How do you fix needless re-renders?** Measure with the React DevTools Profiler first. Then move state down to where it is used, pass children, use React.memo on stable-prop components and virtualise long lists. memo fails when a prop is a new object or function each render.
- **Q21. What is React Compiler, and is memo still needed?** A build-time tool that memoises components and Hooks automatically. Version 1.0 shipped on 7 October 2025 and supports React 17 to 19. The docs say to rely on it for new code and keep useMemo for precise control, such as effect dependencies.
- **Q22. How do you keep a slow screen responsive?** Split code by route with React.lazy (16.6) inside Suspense, defer heavy updates with useDeferredValue or startTransition, virtualise long lists and debounce typing (Q35). Test a production build, since Strict Mode makes development slower.
- **Q23. What are <Activity>, <ViewTransition> and Fragment refs?**<Activity mode="hidden"> (19.2) hides UI but keeps its state. <ViewTransition> (stable in **19.3**) animates enter, exit, update and shared elements for Transition updates. A ref on <Fragment> (**19.3**) adds events, focus and observers to its children.

## Forms, data, routing, testing and accessibility (Q24 to Q30)

- **Q24. Controlled or uncontrolled inputs?** A controlled input keeps its value in state through value and onChange, so React is the source of truth and validation is instant. An uncontrolled input keeps the value in the DOM; read it with a ref or FormData on submit.
- **Q25. What are Actions, useActionState, useFormStatus and useOptimistic?React 19** lets a <form action={fn}> or a transition run an async function, and tracks pending state and errors. useActionState returns state, an action and a pending flag. useFormStatus reads the parent form's status. useOptimistic shows an expected value until the request ends.
- **Q26. How should a component fetch data?** Prefer a framework's data layer, Server Components or TanStack Query. A plain useEffect with fetch needs cleanup against race conditions (Q40). **React 19:**use(promise) suspends until it resolves, but the promise must come from a cache or framework, not be created while rendering.
- **Q27. How do error boundaries work?** They catch errors thrown while rendering their children and show a fallback. They must be classes, or the react-error-boundary package, and miss errors in event handlers. **React 19** added onCaughtError and onUncaughtError root options.
- **Q28. How does client-side routing work?** A router intercepts link clicks, changes the URL with the History API, matches a route and renders its components without a reload. React Router and Next.js add nested layouts and dynamic params. A client-side auth check is cosmetic: enforce access on the server.
- **Q29. How do you test React components?** Use Jest or Vitest with React Testing Library, which renders components and queries the DOM as a user would, with getByRole and getByLabelText. Test behaviour, not internal state. Add a few end-to-end tests, for example with Playwright, for key flows.
- **Q30. How do you make a React interface accessible?** Start with semantic HTML: real button, label and heading elements. Use htmlFor and hyphenated aria-* attributes, support the keyboard, move focus with refs when content changes, and use Fragments to keep list markup valid. eslint-plugin-jsx-a11y lints common mistakes.

## Next.js and Server Components (Q31 to Q34)

- **Q31. What are Server and Client Components?** Server Components render on the server or at build time, can read databases directly and ship no component code to the browser; stable in **React 19**. Client Components, marked 'use client', run in the browser for state, effects and events. In the Next.js App Router, pages are Server Components by default.
- **Q32. What are Server Actions, and what is the main risk?** Async functions marked 'use server' that Client Components can call. Treat each as a public endpoint: validate input and check permissions inside. React disclosed a critical remote code execution flaw in Server Components on 3 December 2025, so patch React and Next.js.
- **Q33. What is hydration, and what causes a mismatch?** Hydration attaches event handlers to server-rendered HTML. A mismatch occurs when the first client render differs, for example from Date.now(). Render the same output, use effects for browser-only values and useId for IDs. **19.3:**use(browser()) opts a component out of server rendering.
- **Q34. What changed in Next.js 16 caching?** Released 22 October 2025, it added Cache Components: dynamic code runs at request time by default, and you opt into caching with 'use cache' after setting cacheComponents: true. Middleware became proxy.ts. npm's latest on 11 November 2026 is 16.4.6.

## Six coding problems (Q35 to Q40)

Say each choice aloud as you write. The plain JavaScript blocks ran under Node 24; output is in the comments.

- **Q35. Write debounce.** Return a function that waits wait milliseconds after the last call before running fn; each call clears the previous timer. In React, create it once, or debounce the value instead.
function debounce(fn, wait) { let timer; return function (...args) { clearTimeout(timer); // a new call cancels the pending one timer = setTimeout(() => fn.apply(this, args), wait); }; } const search = debounce((q) => console.log("search for", q), 50); search("r"); search("re"); search("rea"); search("reac"); // four fast calls, only the last counts setTimeout(() => search("react"), 120); // a pause, then one more call // prints: search for reac // search for react

- **Q36. Write a deep clone.** Say first that structuredClone is built in (Node 17, browsers since March 2022). It handles cycles and dates but throws on functions. A hand-written version uses a WeakMap of copies so cycles end. JSON.parse(JSON.stringify(x)) drops functions and turns dates into strings.
function deepClone(value, seen = new WeakMap()) { if (value === null || typeof value !== "object") return value; if (seen.has(value)) return seen.get(value); // already copied: reuse it, so cycles end if (value instanceof Date) return new Date(value); const copy = Array.isArray(value) ? [] : {}; seen.set(value, copy); for (const key of Object.keys(value)) copy[key] = deepClone(value[key], seen); return copy; } const original = { name: "Asha", tags: ["js"], joined: new Date(2026, 0, 5), address: { city: "Pune" } }; original.self = original; // a cycle const copy = deepClone(original); copy.address.city = "Delhi"; console.log(original.address.city, copy.address.city); // Pune Delhi console.log(copy.self === copy, copy.joined instanceof Date); // true true console.log(structuredClone(original).address.city); // Pune try { structuredClone({ run() {} }); // functions cannot be cloned } catch (e) { console.log(e.name); // DataCloneError }

- **Q37. Turn a flat list of comments into a tree and render it.** Index items by ID, then attach each to its parent's children, or to the roots if the parent is missing: one pass, O(n). Render recursively with a key at each level.
function buildTree(items) { const byId = new Map(items.map((i) => [i.id, { ...i, children: [] }])); const roots = []; for (const node of byId.values()) { const parent = byId.get(node.parentId); (parent ? parent.children : roots).push(node); // no parent found means a top-level item } return roots; } function outline(nodes, depth = 0) { return nodes.flatMap((n) => [" ".repeat(depth) + n.text, ...outline(n.children, depth + 1)]); } const flat = [ { id: 1, parentId: null, text: "Is React still worth learning?" }, { id: 2, parentId: 1, text: "Yes, jobs still ask for it" }, { id: 3, parentId: 2, text: "Learn hooks first" }, { id: 4, parentId: null, text: "Next.js or plain React?" }, { id: 5, parentId: 1, text: "Build one project to see" }, ]; console.log(outline(buildTree(flat)).join("\n")); // Is React still worth learning? // Yes, jobs still ask for it // Learn hooks first // Build one project to see // Next.js or plain React?function Comment({ node }) { return ( <li> {node.text} {node.children.length > 0 && ( <ul> {node.children.map((child) => ( <Comment key={child.id} node={child} /> ))} </ul> )} </li> ); } // usage: <ul>{buildTree(flat).map((n) => <Comment key={n.id} node={n} />)}</ul>

- **Q38. Write a reducer for a task list.** Return new arrays and objects, never mutate, and throw on unknown actions. It is a pure function, so you test it without rendering. Wire it up with useReducer(taskReducer, []).
function taskReducer(state, action) { switch (action.type) { case "add": return [...state, { id: action.id, text: action.text, done: false }]; case "toggle": return state.map((t) => (t.id === action.id ? { ...t, done: !t.done } : t)); case "remove": return state.filter((t) => t.id !== action.id); default: throw new Error("Unknown action: " + action.type); } } const start = []; let state = taskReducer(start, { type: "add", id: 1, text: "Revise hooks" }); state = taskReducer(state, { type: "add", id: 2, text: "Build a task tracker" }); state = taskReducer(state, { type: "toggle", id: 1 }); state = taskReducer(state, { type: "remove", id: 2 }); console.log(JSON.stringify(state)); // [{"id":1,"text":"Revise hooks","done":true}] console.log(start.length); // 0, the old state was never mutated

- **Q39. This timer sticks at 1. Why, and how do you fix it?** The effect runs once, so the callback closes over the first seconds, which is 0, and every tick sets 1. Use the updater form, setSeconds(s => s + 1); adding seconds as a dependency also works but resets the interval.
// Bug: the effect runs once, so `seconds` is always 0 inside it. The display sticks at 1. // useEffect(() => { // const id = setInterval(() => setSeconds(seconds + 1), 1000); // return () => clearInterval(id); // }, []); // Fix: ask React for the latest value with an updater function. function Timer() { const [seconds, setSeconds] = useState(0); useEffect(() => { const id = setInterval(() => setSeconds((s) => s + 1), 1000); return () => clearInterval(id); // stop the timer on unmount }, []); return <p>{seconds}s</p>; }

- **Q40. Write a useUser(id) Hook that avoids race conditions.** If id changes mid-request, a slow old response must not overwrite the new one. Abort the old request in cleanup, ignore AbortError, and treat a stored result for another id as loading.
function useUser(id) { const [result, setResult] = useState({ id: null, data: null, error: null }); useEffect(() => { const controller = new AbortController(); fetch(`/api/users/${id}`, { signal: controller.signal }) .then((res) => { if (!res.ok) throw new Error("HTTP " + res.status); return res.json(); }) .then((data) => setResult({ id, data, error: null })) .catch((error) => { if (error.name !== "AbortError") setResult({ id, data: null, error }); }); return () => controller.abort(); // a newer id cancels the older request }, [id]); const loading = result.id !== id; // the stored result belongs to another id return { data: loading ? null : result.data, error: loading ? null : result.error, loading }; }

## How interviewers judge answers, and what to build

No company publishes its rubric, so this is our reading, not survey data. Interviewers tend to listen for correct behaviour, the reason and the version it applies to. One sentence from your own project, such as 'I hit a stale closure in my timer', beats a memorised paragraph.

Build one app with routing, a form, fetched data and tests first: the [frontend project ideas](https://www.masaischool.com/resources/projects/frontend-project-ideas) and [JavaScript practice projects](https://www.masaischool.com/resources/projects/javascript-practice-projects) pages have starters. For coding rounds, use the [data structures and algorithms path](https://www.masaischool.com/resources/data-structures-and-algorithms) and [DSA interview questions](https://www.masaischool.com/resources/dsa-interview-questions).

## Frequently asked questions

### What are the most asked React interview questions?

Expect JSX, props versus state, keys, the Rules of Hooks, useState, useEffect, useRef, re-rendering, Context versus a store, forms and a small coding task. Master Q5, Q7, Q8, Q14 and Q20 first. No company publishes its question bank, so this is our reading.

### Is React still worth learning in 2026?

The 2026 Stack Overflow survey found 42% of respondents had done extensive work with React in the past year, second to Node.js at 46%. That is a global survey, not an India hiring count. Google Trends India shows searches for react interview questions at about 44% of a year earlier.

### What changed in React 19 that interviewers ask about?

Actions with useActionState and useOptimistic, the use API, ref as a prop instead of forwardRef, <Context> as a provider and stable Server Components. Then <Activity> and useEffectEvent (19.2) and <ViewTransition> (19.3).

### Do I still need useMemo and useCallback with React Compiler?

Less often. React Compiler 1.0 memoises automatically, and the docs recommend relying on it for new code. Keep both for precise control, such as a stable effect dependency. Understand both anyway, because existing code uses them.

### How should a fresher prepare for a React interview?

Build one small app with routing, a form and fetched data. Rehearse the 40 answers aloud, solve the six coding problems without looking and explain a bug you fixed. Revise closures, promises and the event loop, which React rounds also test.

## Sources checked

- [React versions and release dates](https://react.dev/versions)
- [React 19.3 announcement](https://react.dev/blog/2026/09/09/react-19-3)
- [React 19 announcement](https://react.dev/blog/2024/12/05/react-19)
- [React 19.2 announcement](https://react.dev/blog/2025/10/01/react-19-2)
- [React Compiler 1.0](https://react.dev/blog/2025/10/07/react-compiler-1)
- [forwardRef deprecation note](https://react.dev/reference/react/forwardRef)
- [Class components and error boundaries](https://react.dev/reference/react/Component)
- [Next.js 16 release post](https://nextjs.org/blog/next-16)
- [Stack Overflow 2026 web frameworks](https://survey.stackoverflow.co/2026/technology/data)
- [npm latest tag for react](https://registry.npmjs.org/react)
