Interview questions with answers
React 19+ interview questions and answers
Actions, use(), useOptimistic, Server Components and the React Compiler. Open any question to read its model answer; the multiple-choice set marks the right option and explains it.
- Subjective
- 30
- Objective
- 30
Subjective questions 30
1What are the main features of React 19?Asked almost every time
Actions: async functions in transitions that manage pending state, errors and optimistic updates, with useActionState, useFormStatus and useOptimistic, and <form action={fn}>. The use() API reads promises and context during render. Server Components and Server Actions are stable. ref is a normal prop for function components, <Context> works as a provider, document metadata tags can be rendered anywhere, and stylesheet and script loading are integrated with Suspense.
2How does reconciliation work, and why do keys matter?Asked almost every time
On each render React builds a new element tree and diffs it with the previous one. Elements of the same type at the same position are updated in place; a different type remounts the subtree. In lists, key tells React which item is which, so it can move, add or remove items correctly. Index keys break when items are reordered or inserted: state and DOM get attached to the wrong item.
3Explain useEffect, its dependencies and cleanup.Asked almost every time
useEffect runs after the commit to synchronise with something outside React: subscriptions, timers, network requests, DOM APIs. The dependency array lists the reactive values it uses; it re-runs when they change. The returned cleanup runs before the next run and on unmount. In development Strict Mode runs effects twice to expose missing cleanup. Do not use effects for derived data or event-driven logic.
4What is the React Compiler and how does it change memoisation?Asked almost every time
The React Compiler is a build-time tool that automatically memoises components and values based on their dependencies, so you rarely need useMemo, useCallback or memo by hand. It assumes your code follows the Rules of React (pure render, no mutation of props or state). Next.js 16 and Vite can enable it in config.
5What is the virtual DOM and is it still a useful idea?Asked almost every time
React builds a tree of elements describing the UI, compares it with the previous one, and applies the minimal changes to the real DOM. The point is a declarative model (describe the UI for the current state) with efficient updates, not that it is always faster than hand-written DOM code.
6How does React batch state updates?Asked almost every time
Since React 18, updates inside event handlers, promises, timeouts and native events are batched automatically, so several setState calls cause one re-render. flushSync forces an immediate update when you truly need the DOM updated synchronously.
7What are the rules of hooks and why do they exist?Asked almost every time
Call hooks only at the top level of components or custom hooks, never in conditions, loops or after early returns. React identifies each hook by call order, so changing the order between renders would mix up their state.
8How do you lift state up and when should you?Asked almost every time
When two components need the same changing data, move it to their closest common parent and pass it down with props and callbacks. This keeps a single source of truth. If many distant components need it, consider context or a store instead.
9How do useOptimistic and useActionState work together?Very often asked
useActionState(action, initial) wraps an action and gives you its latest returned state and a pending flag. useOptimistic(state, update) shows a temporary value immediately while the action runs, then React swaps in the real state when it finishes, or reverts if it fails. Together they make forms feel instant.
10What does the use API do?Very often asked
use(promise) suspends the component until the promise resolves and returns its value, and use(context) reads context. Unlike hooks, use can be called inside conditions and loops. Promises should come from a cache or be created by a Server Component and passed down, not created on every render.
11What problems do Server Components solve?Very often asked
They run only on the server, so they can read data directly, keep secrets private, and send zero JavaScript for their own code. Large libraries used only for rendering stay off the client. They compose with Client Components for interactivity, cutting bundle size and request waterfalls.
12When should state live in a component, in context, or in an external store?Very often asked
Keep state as close as possible to where it is used. Lift it to the nearest common parent when siblings need it. Use context for values many components read but rarely change, such as theme or the current user. Use an external store (Zustand, Redux Toolkit) for complex, frequently updated shared client state, and a server-cache library (TanStack Query) for server data.
13What are transitions and useTransition for?Very often asked
A transition marks an update as non-urgent. React keeps the UI responsive to urgent input (typing) while it renders the transition in the background, and can interrupt it. useTransition returns isPending and startTransition; in React 19 the function can be async, which is the basis of Actions.
14What is context and what are its performance pitfalls?Very often asked
Context passes values through the tree without props. Every consumer re-renders when the provider value changes, so passing a new object each render or putting fast-changing data in a broad context causes many re-renders. Split contexts, memoise values, or use a store with selectors.
15How do you write a custom hook?Very often asked
A function starting with use that calls other hooks to package reusable logic, such as useDebounce or useOnlineStatus. Each component using it gets its own state; custom hooks share logic, not state.
16When should you not use useEffect?Very often asked
For deriving data from props or state (compute it during render), for handling user events (do it in the handler), or for resetting state when a prop changes (use a key). Effects are for synchronising with external systems such as subscriptions, timers or the DOM.
17How do Suspense boundaries work?Very often asked
A <Suspense fallback> shows its fallback while a child is waiting for data or code (lazy components, use(promise), framework data). Nested boundaries let parts of the page appear independently, and transitions keep current content visible instead of falling back again.
18How do refs work and when do you use them?Very often asked
useRef holds a mutable value that persists across renders without causing re-renders. Use it for DOM nodes (focus, measure, scroll), timers or previous values. In React 19, refs can be passed as props and ref callbacks can return cleanup functions.
19What is code splitting and how do you do it in React?Very often asked
Splitting the bundle so code loads only when needed: const Chart = lazy(() => import('./Chart')) inside a <Suspense> boundary. Split by route and by heavy, rarely used components.
20Controlled vs. uncontrolled inputs: what is the difference?Often asked
A controlled input gets its value from state and reports changes through onChange, so React is the source of truth. An uncontrolled input keeps its own value in the DOM, read with a ref or from FormData on submit. React 19 form actions make uncontrolled forms with FormData very convenient.
21How do error boundaries work?Often asked
A class component with getDerivedStateFromError or componentDidCatch catches errors thrown while rendering its children and shows a fallback. They do not catch errors in event handlers or async code. Frameworks such as Next.js provide them through error.tsx, and react-error-boundary offers a hook-friendly wrapper.
22What is the Activity component in React 19.2?Often asked
<Activity mode="visible" | "hidden"> hides a subtree without unmounting it: effects are cleaned up and updates are deferred while hidden, but state is kept, so switching back (such as between tabs) is instant and keeps form input.
23How do you avoid unnecessary re-renders?Often asked
Keep state local, split components so changes affect smaller trees, pass children instead of rendering them inside a stateful parent, avoid creating new objects in props when not needed, use selectors with stores, and let the React Compiler memoise. Measure with the React DevTools Profiler before optimising.
24How do portals work?Often asked
createPortal(children, domNode) renders children into another DOM node, such as document.body for modals and tooltips, while they stay in the React tree for context and event bubbling.
25What are React 19 document metadata features?Often asked
Components can render <title>, <meta> and <link> tags anywhere, and React hoists them into the document head. Stylesheets with precedence and async scripts are deduplicated and ordered correctly.
26How do you handle forms in React 19?Often asked
Pass a function to <form action={fn}>; React calls it with FormData, handles pending state (useFormStatus), and resets uncontrolled fields after success. useActionState adds returned state such as errors, and useOptimistic shows instant results.
27What is useDeferredValue?Often asked
It returns a lagging copy of a value that updates at lower priority, so an expensive child (like a filtered list) re-renders after urgent updates (like typing). Combined with memo, it keeps inputs responsive.
28How do you test React components?Often asked
Render them with React Testing Library, find elements by role and label like a user would, interact with user-event, assert on visible results, and mock network calls with MSW rather than mocking components.
29What does Strict Mode do in development?Sometimes asked
It double-invokes render functions and effects (mount, unmount, mount) to reveal impure rendering and missing cleanups, and warns about deprecated APIs. It has no effect in production.
30What is useSyncExternalStore for?Sometimes asked
Subscribing to external stores (state libraries, browser APIs) in a way that is safe with concurrent rendering, avoiding tearing where different parts of the UI show different values.
Objective questions 30
1Which hook manages the state returned by a form action?Asked almost every time
Why: React 19 renamed the canary useFormState to useActionState.
2In React 19, how do function components receive a ref?Asked almost every time
Why: ref is now a normal prop; forwardRef is no longer needed.
3Why should list keys be stable and unique?Asked almost every time
Why: Keys identify items for correct updates, moves and state preservation.
4When does an effect's cleanup run?Asked almost every time
Why: Cleanup undoes the previous run's setup.
5Where may hooks be called?Asked almost every time
Why: Order must be the same every render.
6Since React 18, updates in timeouts and promises are…Asked almost every time
Why: Automatic batching applies everywhere.
7How do you reset a component's state when an id changes?Asked almost every time
Why: A new key remounts it.
8Which hook shows a temporary value while an action runs?Very often asked
Why: useOptimistic renders an optimistic state until the action settles.
9What can use() do that hooks cannot?Very often asked
Why: use is not bound by the rule of calling hooks at the top level.
10Which hook reads the pending state of the parent form?Very often asked
Why: useFormStatus (react-dom) reports whether the enclosing form is submitting.
11What does the React Compiler do?Very often asked
Why: It inserts memoisation so manual useMemo/useCallback are rarely needed.
12Which function lazy-loads a component?Very often asked
Why: Pair it with Suspense.
13What does createPortal do?Very often asked
Why: Events still bubble through React.
14Why can a context cause many re-renders?Very often asked
Why: Split or memoise values.
15Which hook lets a slow child lag behind fast input?Very often asked
Why: It defers a value at low priority.
16Which should you NOT use an effect for?Very often asked
Why: Compute it during render.
17Which directive marks a module as a Client Component?Often asked
Why: It marks the boundary where client code starts.
18What marks a state update as non-urgent?Often asked
Why: Transitions can be interrupted by urgent updates.
19Error boundaries do NOT catch errors in…Often asked
Why: Event handler errors must be handled with try/catch.
20Which hook generates IDs stable between server and client?Often asked
Why: useId avoids hydration mismatches for accessibility attributes.
21What does useRef change cause?Often asked
Why: Refs are mutable boxes.
22Which hook subscribes safely to external stores?Often asked
Why: It prevents tearing.
23Custom hooks share…Often asked
Why: Each call has its own state.
24In React 19, a <title> rendered in a component…Often asked
Why: Built-in metadata support.
25Which function forces a synchronous DOM update?Often asked
Why: Use rarely.
26What does <form action={fn}> pass to fn?Often asked
Why: React 19 form actions.
27What does <Activity mode="hidden"> keep while hidden?Sometimes asked
Why: State is preserved; effects are cleaned up until it is visible again.
28Which hook runs synchronously after DOM mutations but before paint?Sometimes asked
Why: useLayoutEffect is for measuring layout before the browser paints.
29What does a Suspense fallback show?Sometimes asked
Why: Error boundaries handle errors.
30What can React 19 ref callbacks return?Sometimes asked
Why: It runs when the element is removed.
Track what you have practised and search every bank in your dashboard.
Start learning