Skip to content
Tutorials Center
My learning

Topics

Lesson 132 of 132 ยท Practice and Review

React Interview Questions and Answers

67 React interview questions with concise, accurate answers: rendering, keys, hooks, state, context, performance, patterns and React 19, plus runnable examples that prove the tricky ones.

A React interview rarely checks whether you can recite an API. It checks whether you have a correct mental model: what triggers a render, what a render is allowed to do, why state behaves like a snapshot, and when an effect is the right tool. The questions below are the ones that come up again and again, grouped by topic, with short answers you could say out loud in under a minute. Several of the trickiest answers come with a runnable example, because "I have seen it happen" is a stronger answer than "I read it somewhere".

How to use this page:

  • Do not memorise the sentences. Read the question, answer it aloud in your own words, then compare. The bold phrases are the points interviewers listen for.
  • Follow the links. Each answer points to the lesson that explains the idea in depth. If a link feels unfamiliar, read that lesson before moving on.
  • Practise the follow-ups. Good interviewers ask "why?" and "what would break if...?". Where we know a common follow-up, it is in the answer.
  • Know the version. This page targets React 19. If a question mentions forwardRef, class components or ReactDOM.render, say that they exist in older code and what replaces them.

The runnable examples use the React 19 development build. They use <StrictMode> only where we say so.

Fundamentals

1. What is React and what problem does it solve?

React is a JavaScript library for building user interfaces out of components. Its core idea is that the UI is a function of state: you describe what the screen should look like for the current data, and React works out the minimal DOM changes needed to get there. It removes the need to hand-write "find this node, change that attribute" code. See introduction and how React works.

2. What is JSX? Is it required?

JSX is a syntax extension that lets you write markup-like expressions in JavaScript. A build tool (Babel, SWC, esbuild) compiles each element into a function call that creates a React element object. It is not required: you can call createElement or the jsx function yourself, but nobody does. JSX is not HTML: attributes are camelCase (className, htmlFor), every tag must be closed, and {} embeds JavaScript expressions, not statements. See JSX basics.

3. What is the difference between an element and a component?

A component is a function (in modern React) that takes props and returns something renderable. An element is the plain object description that JSX produces, such as { type: 'button', props: {...} }. Calling <Button /> creates an element whose type is your function; React later calls the function to find out what it renders. Elements are cheap, immutable descriptions, not DOM nodes.

4. What is the difference between props and state?

Props are inputs passed from a parent and are read-only for the receiving component. State is memory that a component owns and changes over time, via a setter that triggers a re-render. A useful test: if the value comes from the parent, it is a prop; if it changes because of something the user did inside this component and must be remembered, it is state; if it can be computed from either, it is neither. See props and useState.

5. Why must you not modify props?

Components are supposed to be pure with respect to their inputs: same props and state in, same JSX out. Mutating a prop changes data that belongs to the parent, so other components can see an inconsistent value and React cannot know that a re-render is needed. If a child needs a changed value, the parent passes a callback (onChange) or the child copies the data into its own state. See pure components.

6. What are keys for and why not use the array index?

A key gives each item in a list a stable identity so React can match old and new children between renders. With a stable id, React moves, keeps or removes the right DOM nodes and preserves each item's state. With an index, inserting or reordering shifts every identity: input text, focus and component state then appear on the wrong rows. Index keys are acceptable only for lists that never reorder, insert or delete. A missing key triggers a development warning. See lists and keys.

7. What is a Fragment and why would you use it?

A fragment (<>...</> or <Fragment key={id}>) groups children without adding a DOM element. Components must return a single root, and an extra <div> can break layouts such as table rows, flex or grid children. Use the long <Fragment key=...> form when a fragment is an item in a list.

8. What are controlled and uncontrolled form elements?

A controlled input gets its value from state (value + onChange), so React is the single source of truth and you can validate or transform on every keystroke. An uncontrolled input keeps its value in the DOM; you read it on submit through a ref or FormData. Prefer uncontrolled with form actions for simple forms, and controlled when the UI must react to each change. See controlled and uncontrolled and forms and inputs.

9. Why do component names have to start with a capital letter?

JSX treats lowercase tags as built-in DOM elements (<div>) and capitalised ones as references to variables (<Card> means the value Card). A lowercase name is looked up as an HTML tag, and you get an unknown element in the DOM instead of your component. Member expressions such as <Menu.Item /> are also treated as components.

10. How do you render conditionally, and what is the 0 && pitfall?

Use if before the return, a ternary (a ? <A /> : <B />), or && (ok && <A />). false, null and undefined render nothing, but 0 renders as the text 0. So {items.length && <List />} prints 0 for an empty list. Use items.length > 0 && <List /> or a ternary. See conditional rendering.

Rendering

11. What are the render phase and the commit phase?

Render means React calls your components to compute the next tree of elements. It must be pure and can be paused, restarted or thrown away, especially with concurrent features. Commit means React applies the minimal changes to the DOM, then runs layout effects, then (after paint, usually) passive effects. Side effects therefore belong in event handlers or effects, never in the render body. See rendering in depth.

12. What triggers a re-render?

Three things: the component's own state changed (a setter was called with a different value), its parent re-rendered (props are not compared unless you wrap it in memo), or a context it reads changed. Changing a ref, a plain variable or calling forceUpdate-like tricks does not render. Rendering is also not the same as touching the DOM: a component can render and produce identical output, in which case React changes nothing in the DOM.

13. What is the virtual DOM and what is reconciliation?

The "virtual DOM" is the tree of React elements your components return. Reconciliation is React's algorithm for comparing the previous tree with the next one and computing the smallest set of DOM operations. It is not faster than hand-written DOM code in every case; its value is that you write declarative code and React batches and minimises the work. See reconciliation.

14. What assumptions does the diffing algorithm make?

Two heuristics keep diffing linear instead of cubic: elements of different types produce different trees (React tears down the old subtree and builds a new one), and keys hint which children are stable across renders. Same type at the same position means "update in place and keep state". This is why defining a component inside another component is a bug: its type changes every render, so state is reset each time.

15. Why does setCount(count + 1) three times add only one?

State is a snapshot for each render: count is a constant within that render's closure. Three calls all say "set to 0 + 1". React also batches updates from one event into a single re-render. Use the updater form, setCount((n) => n + 1), when the next value depends on the previous one. Run it:

Snapshot state and updater functions

After one click the page shows plain: 1 and updater: 3, and the console prints inside the handler, plain is still 0: the variable did not change in the middle of the handler. See state updates.

16. How can you reset a component's state on purpose?

Give it a different key. When the key changes, React treats it as a new component instance: it unmounts the old one (discarding state) and mounts a new one. This is the clean way to reset a form when the selected user changes, without an effect. In the demo, both drafts receive the same text, but only the keyed one is reset when the user switches:

A key change resets state

Type into both inputs, then press the button: the first keeps your text, the second empties. See reconciliation.

17. What does <StrictMode> do?

In development only, it renders components twice and runs each effect's setup, cleanup and setup again on mount (it also re-runs ref callbacks). The goal is to surface impure renders and missing cleanup early. It has no effect in production. The console in this example shows it:

StrictMode doubles renders and effects

On mount the console shows render, render, effect: connect, cleanup: disconnect, effect: connect. Hiding the child logs only cleanup: disconnect. If your effect breaks when it is set up twice, it lacks proper cleanup.

18. What does it mean for a component to be pure?

For the same props, state and context it must return the same JSX, and it must not change anything that existed before it started rendering (no mutating outside variables, no network calls, no Math.random() or Date.now() in output). Local variables created during render are fine to mutate. Purity is what allows React to retry, pause and double-render safely. See pure components.

19. I pushed to a state array and called the setter. Why did nothing happen?

React compares the old and new state with Object.is. The same array reference means "no change", so it skips the render. Always produce a new array or object. The log shows the trap: the first click mutates, nothing renders, and the pushed item appears only later, when another update creates a new array.

Mutation versus a new array

Click Push and the page still says a, b although the log says the length is 3. Click Spread and the page jumps to a, b, c, d. See objects and arrays in state.

20. Does a parent re-render always re-render its children?

Yes, by default: when a component renders, all the child elements it creates are re-rendered recursively, whether or not their props changed. Two ways to stop it: wrap a child in memo (skips when props are shallow-equal), or pass the child as children from a higher component so the element object is the same one as before. Watch the console in this experiment:

Who re-renders when the parent does

Clicking Wrapper count logs Wrapper rendered and two Plain rendered lines, but no Memoized rendered. Clicking Count (the state inside Counter) logs nothing at all, because the Plain element it shows was created by Wrapper and did not change. See memo and rendering in depth.

Hooks

21. What are the rules of hooks, and why do they exist?

Call hooks only at the top level of a component or custom hook (never in loops, conditions, nested functions or after an early return), and only from React functions. React identifies each hook by its call order on every render, so the order must never change. The ESLint plugin eslint-plugin-react-hooks enforces both rules. See rules of hooks.

22. What is a lazy initial state?

useState(expensive()) runs expensive() on every render and throws the result away after the first. useState(() => expensive()) passes a function that React calls only once, on the first render. Use it for parsing, large allocations or reading from storage. useState(0) and other cheap values need no function.

23. When does useEffect run?

After React has committed the render to the DOM (and normally after the browser has painted), for every render where its dependencies changed; on mount the dependencies count as changed. The effect function runs after the previous run's cleanup. In development with StrictMode, mount runs setup, cleanup, setup. Effects do not run on the server. See useEffect.

24. How does the dependency array work?

React compares each dependency with its value from the previous render using Object.is. [] means "only on mount (and cleanup on unmount)", no array means "after every render", and [a, b] means "when a or b changed". The array must list every reactive value the effect reads. If that creates a loop, fix the code (move the object inside the effect, stabilise it, or use an updater) instead of silencing the linter. See effect dependencies.

25. Why return a cleanup function from an effect?

Effects start things (subscriptions, timers, listeners, requests). Cleanup stops them. React calls cleanup before the next run of that effect and when the component unmounts. Without it you leak timers, stack up listeners and get stale responses that overwrite fresh ones. See effect cleanup.

26. When should you not use an effect?

When you only transform data you already have or respond to a user action. Examples: compute derived values during render (const total = items.reduce(...)), handle clicks and submits in event handlers, reset state with a key, and use useSyncExternalStore for external stores. An effect that does setState from other state is usually a smell. See you might not need an effect.

27. What is useRef and how does it differ from state?

useRef returns a mutable box ({ current }) that persists across renders and does not cause a re-render when changed. Use it for DOM nodes, timer ids and other values that are not part of what the screen shows. If the UI must update when a value changes, it is state. Do not read or write ref.current during render, except for lazy initialisation. See useRef.

28. What is the difference between useMemo and useCallback?

useMemo(() => compute(a), [a]) caches a value; useCallback(fn, deps) caches a function (it is useMemo(() => fn, deps)). Both are performance hints, not semantic guarantees: React may discard the cache. Use them to avoid an expensive calculation or to keep a stable reference for memo children and effect dependencies, not by default everywhere. See useMemo and useCallback.

29. When would you choose useReducer over useState?

When state is an object with several fields that change together, when the next state depends on complex rules, or when many handlers update the same state. A reducer centralises the rules in a pure (state, action) => state function that is easy to test and to log. useState is simpler for independent values. See reducers.

30. How does context work, and what is its cost?

createContext makes a channel, a provider supplies a value, and any descendant reading it with useContext gets the nearest provider's value. Every consumer re-renders when the provided value changes (compared with Object.is), regardless of which part of the value it uses. So avoid putting fast-changing data and an object literal created each render in one provider; split contexts by update frequency and memoise the value. In React 19 you write <ThemeContext value={...}>. See context and context patterns.

31. What is the difference between useEffect and useLayoutEffect?

useLayoutEffect runs synchronously after DOM mutations but before the browser paints, so you can measure layout and adjust it without flicker; it blocks painting, so keep it short. useEffect runs after paint. Reach for useLayoutEffect only when you must read layout and re-render before the user sees a frame (tooltips, scroll restoration). See useLayoutEffect and others.

32. What is useId for?

It generates a unique, stable id that matches between server and client rendering, which you use for htmlFor/id and ARIA attributes in reusable components. Never use it as a list key, and treat the string as opaque: its format changes between React versions.

33. What do useTransition and useDeferredValue do?

Both mark updates as non-urgent so urgent ones (typing, clicking) stay responsive. useTransition gives you startTransition to wrap a state update and an isPending flag; React can interrupt the transition render if something urgent arrives. useDeferredValue(value) returns a value that lags behind during heavy re-renders. In React 19 transitions can wrap async functions too. See transitions.

34. What is a custom hook?

A function whose name starts with use and that calls other hooks to package stateful logic for reuse (useToggle, useDebouncedValue, useOnlineStatus). Each call gets its own state; hooks share logic, not state. They are the main replacement for render props and higher-order components. See custom hooks.

35. What is a stale closure in React?

A function created during one render remembers that render's values. A timer or listener set up in an effect with [] that reads count will keep reading the initial count. Fixes: use the updater form of the setter, list the value as a dependency (and clean up), or read the latest value through a ref or useEffectEvent.

36. What is useEffectEvent?

It wraps a function so you can call it from an effect and always see the latest props and state, without making that function a dependency that re-runs the effect. Use it for "when the connection opens, show a toast with the current theme" where the theme should not reconnect. Only call it from effects, never pass it down as a prop. This is how it behaves:

useEffectEvent reads the latest value

Change the theme and nothing reconnects (the effect depends only on roomId), yet the next room switch logs the new theme. See useEffectEvent.

State and patterns

37. What does "lifting state up" mean?

When two components need the same changing data, move the state to their closest common parent and pass it down as props, with callbacks for changes. This keeps one source of truth. If it makes the parent pass props through many layers, consider composition or context. See lifting state up.

38. How does React favour composition over inheritance?

You build bigger components by combining smaller ones through props and children, not by extending classes. A Dialog accepts children or named element props; a PrimaryButton is a Button rendered with specific props. There is no use case in the React docs that requires inheritance. See children and composition.

39. How do higher-order components and render props compare with hooks?

All three share logic. A HOC is a function that takes a component and returns an enhanced one. A render prop passes a function child that renders with shared data. Both nest awkwardly ("wrapper hell") and hide where props come from. Custom hooks share the same logic with a plain function call and no extra nesting, so they are the default today; HOCs and render props survive in libraries and a few cases that need to control rendering. See render props and HOCs.

40. What is the compound component pattern?

A set of components that work together by sharing implicit state through context, such as Tabs, TabButton and TabPanel, or <select> and <option>. The consumer composes the pieces freely, and the parent manages state. See compound components.

41. What are error boundaries and what do they not catch?

An error boundary is a class component with static getDerivedStateFromError (and optionally componentDidCatch) that renders a fallback when a descendant throws while rendering. It does not catch errors in event handlers, asynchronous code (timers, promises), server rendering or the boundary itself. Function components cannot be boundaries; libraries such as react-error-boundary provide a ready-made one. The sketch is read-only (class syntax is not part of our runnable lessons):

JSX
// Read-only sketch: a minimal error boundary.
class ErrorBoundary extends React.Component {
  state = { hasError: false };

  static getDerivedStateFromError() {
    return { hasError: true };
  }

  render() {
    return this.state.hasError ? <p>Something went wrong.</p> : this.props.children;
  }
}

See error boundaries.

42. What is a portal?

createPortal(children, domNode) renders children into a different DOM node (often document.body) while keeping them in the same React tree, so context and event bubbling still work. It is the standard tool for modals, tooltips and dropdowns that must escape overflow: hidden or stacking contexts. See portals.

43. What are Suspense and lazy used for?

lazy(() => import('./Chart')) code-splits a component into a separate bundle that loads when first rendered. <Suspense fallback={...}> shows a fallback while anything inside is suspended, which includes lazy components and data read with use(). Together they let the UI declare its loading states instead of every component tracking isLoading. The example reads a cached promise with use:

use and Suspense

The page shows Loading... for a moment, then Hello, Ada!. The promise comes from a cache: creating a new promise on every render would suspend forever. See use and Suspense and code splitting.

44. How do you avoid prop drilling?

In order of preference: restructure with composition (pass the already-built element as children or a slot prop), keep state close to where it is used, use context for truly global-ish values (theme, current user, locale), and use an external store for complex shared state. See context and state management.

45. Context versus Redux, Zustand or TanStack Query: how do you choose?

Context is a transport for a value, not a state manager: it has no selectors, so all consumers re-render on any change. Use it for rarely changing values. Use a store library when many components read different slices of fast-changing client state. Use a server-state library (TanStack Query, SWR or a framework loader) for data that lives on a server, because caching, deduplication and revalidation are the hard parts. See state management and caching and server state.

Performance

46. How do you find and fix performance problems in React?

Measure first with the React DevTools Profiler (why did it render, how long it took). Then fix the cause: move state down so fewer components render, split slow parts, pass children to avoid re-creating elements, use memo with stable props, useMemo for truly expensive computations, virtualise long lists, defer non-urgent work with transitions, and code-split heavy routes. Premature useMemo everywhere adds cost and noise. See profiling and virtualization.

47. What does React Compiler do?

It is a build-time compiler (usually a Babel or bundler plugin) that analyses components and hooks and automatically memoises values and callbacks where it is safe, so you rarely write useMemo, useCallback or memo by hand. It relies on the rules of React: pure render, no mutation of props and state. Code that breaks the rules is skipped or must be fixed. See React Compiler.

React 19 and the ecosystem

48. What are Actions in React 19?

An Action is a function (often async) you hand to a form's action or to startTransition. React tracks the pending state, handles errors with error boundaries, resets uncontrolled forms and keeps the UI consistent. Around it sit useActionState (returned state plus a pending flag), useFormStatus (a child reads its parent form's pending state) and useOptimistic (show the expected result immediately). See form actions, useActionState and useFormStatus and useOptimistic.

49. What does use do, and how is it different from other hooks?

use(resource) reads a promise (suspending until it resolves) or a context (like useContext). Unlike other hooks it can be called conditionally and in loops. The promise must be stable across renders, typically created outside the component or in a cache or by a framework; a promise created during render would restart on every render.

50. What small API changes arrived in React 19?

ref is now a regular prop for function components (no forwardRef in new code); ref callbacks can return a cleanup function; <Context value> replaces <Context.Provider>; <title>, <meta> and <link> rendered anywhere are hoisted into <head>; stylesheets support precedence ordering; and error reporting gained onCaughtError and onUncaughtError root options. See refs and imperative handles.

51. What is the difference between SSR and Server Components?

SSR renders your components to HTML on the server for the first load, then the browser downloads the same JavaScript and hydrates (attaches handlers to) the markup; every component still ships to the client. Server Components run only on the server (or at build time), can read databases directly, and their code is never sent to the browser; Client Components, marked with 'use client', handle interactivity. They need a framework or bundler integration such as Next.js or React Router. See server components and SSR and hydration.

52. What is a hydration mismatch?

During hydration React expects the server HTML to match what the client would render. A difference (Date.now(), Math.random(), window checks, locale-dependent formatting, invalid HTML nesting) logs a mismatch error and may cause React to re-render on the client. Render the same output on both sides on the first pass, then update in an effect, or mark inevitable differences with suppressHydrationWarning on that element.

53. How do you test React components?

Test behaviour as the user sees it: render the component, find elements by role or label (React Testing Library), interact (userEvent), and assert what appears. Avoid testing implementation details such as state values or hook calls. Unit test pure logic (reducers, helpers) separately and use end-to-end tests (Playwright, Cypress) for full flows. See testing React and testing hooks and logic.

Redux, Router and legacy React

Interviewers for older or larger codebases still ask about the tools from before hooks. Short, accurate answers matter here, and so does saying what replaced each thing.

54. What are the core principles of Redux?

One store holds the application state; state changes only by dispatching actions (plain objects with a type); and reducers are pure functions (state, action) => newState that compute the next state without mutating the old one or doing side effects. Data flows one way: dispatch, reduce, notify subscribers. See Classic Redux.

55. What is the difference between connect and the useSelector and useDispatch hooks?

connect(mapStateToProps, mapDispatchToProps)(Component) is a higher-order component that injects state and bound action creators as props. useSelector(selector) and useDispatch() do the same inside a function component without a wrapper. Both subscribe the component to the store, and both re-render it only when the selected value changes (by === for useSelector, shallow comparison for connect's props). New code uses the hooks.

56. Why can a selector cause needless re-renders, and how do you fix it?

If a selector or mapStateToProps builds a new array or object on every call (for example state.todos.filter(...)), the comparison always fails and the component re-renders on every store update. Return a stable reference instead: select the raw slice and derive in the component with useMemo, or use a memoized selector (createSelector from reselect, re-exported by Redux Toolkit).

57. How do you do async work in Redux?

Reducers must be pure, so async code lives in middleware. redux-thunk lets you dispatch a function that receives dispatch and getState, performs the request, and dispatches pending, fulfilled and rejected actions. Redux Toolkit packages this as createAsyncThunk, and RTK Query handles server data with caching. Alternatives are redux-saga (generators) and redux-observable. For server data in new apps, TanStack Query is often a better fit than hand-written thunks.

58. Why did Redux Toolkit replace hand-written Redux?

Classic Redux needed action constants, action creators, switch statements with careful immutable updates and manual store setup. Redux Toolkit's createSlice generates the action creators and types, lets reducers "mutate" a draft through Immer, configureStore wires thunk and DevTools with sensible checks, and createAsyncThunk standardizes async. The concepts are the same; the boilerplate is gone. See Redux Toolkit and Zustand.

59. When do you not need Redux?

When state is local to a component or a small subtree, use useState or useReducer. When it is shared by a few components, lift it up or use context. When it is server data, use a data-fetching library with caching. Redux earns its place when many distant parts of a large app share complex client state, when you need predictable, inspectable updates, time-travel debugging or strict team conventions. See state management.

60. What are the differences between BrowserRouter, HashRouter and MemoryRouter?

They differ in where the location is stored. BrowserRouter uses the History API (clean URLs, requires a server that falls back to index.html). HashRouter keeps the route after # so the server never sees it (works on any static host, uglier URLs). MemoryRouter keeps history in an array, with no URL, for tests, embedded widgets and React Native. See Router types and hooks.

61. What changed from React Router v5 to v6 and v7?

Switch became Routes (matching by best rank rather than first match), component and render became element, exact is no longer needed, Redirect became Navigate, useHistory became useNavigate, useRouteMatch became useMatch, route components no longer receive match, location and history props (use useParams, useLocation), and NavLink takes a function for className. v6.4 added data routers with loaders and actions, and v7 merges Remix features into the framework mode. See React Router.

62. What is the difference between useParams, useLocation and useMatch?

useParams returns the dynamic segments of the route that rendered the component ({ userId: '7' }, always strings). useLocation returns the current location (pathname, search, hash, state). useMatch(pattern) tests the current URL against any pattern and returns a match or null, which is useful in components outside the route, such as a header.

63. Name the lifecycle methods of a class component and their hook equivalents.

constructor and class fields map to useState initial values; componentDidMount to an effect with []; componentDidUpdate to an effect with dependencies; componentWillUnmount to the cleanup function; shouldComponentUpdate and PureComponent to memo; getSnapshotBeforeUpdate to useLayoutEffect-style code; getDerivedStateFromProps to computing in render or resetting with a key. Error boundaries (getDerivedStateFromError, componentDidCatch) still require a class. See Class components and the lifecycle.

64. Why were componentWillMount and componentWillReceiveProps deprecated?

They ran before the render, and concurrent rendering may start a render and abandon it, so side effects in them could run twice or for renders that never appeared. They were renamed with an UNSAFE_ prefix. Initialization moves to the constructor, fetching to componentDidMount, prop-driven side effects to componentDidUpdate, and state resets to a key.

65. What is a higher-order component, and what is its modern alternative?

A higher-order component (HOC) is a function that takes a component and returns an enhanced component, such as connect or withRouter. HOCs wrap the tree (extra layers in DevTools), can clash on prop names and hide where props come from. Custom hooks give the same reuse with explicit, composable calls. See render props and HOCs.

66. Why can a fetch request show a CORS error, and who fixes it?

The browser enforces the same-origin policy: JavaScript may read a cross-origin response only if the server sends Access-Control-Allow-Origin (and related headers, including answers to the preflight OPTIONS request). The fix is on the server or a proxy (a dev-server proxy while developing, your own backend in production), not in React or Axios, and no-cors only hides the response. See Axios, HTTP requests and CORS.

67. What did React 19 remove that older tutorials still use?

propTypes checking and defaultProps on function components (use TypeScript and default parameters), ReactDOM.render and hydrate (use createRoot and hydrateRoot), unmountComponentAtNode and findDOMNode (use root.unmount() and refs), string refs, legacy context and react-test-renderer/shallow. forwardRef still works, but ref is now an ordinary prop for function components. See PropTypes and defaultProps and the ReactDOM tour.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. What does React do when you call a state setter with a value that is Object.is-equal to the current state?

    React compares with Object.is and bails out when the value is the same. That is why mutating an array in place and passing it back does nothing visible.
  2. 2. Which of these is the cleanest way to reset a form's state when the selected user changes?

    A different key makes React discard the old instance and mount a fresh one with initial state, without an effect and an extra render.
  3. 3. A child wrapped in memo still renders on every parent render. What is the most likely reason?

    memo compares props shallowly. An inline object, array or arrow function created in the parent is a new reference on every render and defeats it.
  4. 4. Which errors does an error boundary catch?

    Boundaries catch errors during rendering, lifecycle and constructors of the tree below them. Event handler and async errors need try/catch or state.
  5. 5. In the StrictMode demo, what is logged when the child mounts?

    StrictMode mounts, unmounts and mounts again in development to expose missing cleanup, so you see setup, cleanup, setup.

Summary

  • Interviewers test the mental model: render must be pure, state is a snapshot, updates are batched, and identity (keys, element type, position) decides whether state survives.
  • Know what triggers a render (own state, parent render, context), what does not (refs, mutation), and how to stop unnecessary renders (move state down, children, memo, the Compiler).
  • Effects synchronise with the outside world, need cleanup and complete dependency lists, and are often not needed at all.
  • Keep Object.is in mind: new objects and arrays for state, stable references for memo, effects and context values.
  • For React 19, be ready to explain Actions, useActionState, useOptimistic, use, ref as a prop, <Context value> and where Server Components fit.
  • Back your answers with something you ran: a small experiment beats a memorised sentence.

You have reached the end of the React tutorial. Revisit the cheat sheet and the practice problems whenever you want a quick refresher, and keep building: the projects are the best way to turn these answers into habits.