REACT INTERVIEWS
React interview questions
147 questions about React, the way interviewers ask them: 75 to explain, 40 where you predict what a component logs and shows, and 32 where you write a component or a hook. 35 easy, 84 medium, and 28 hard. Every answer is checked by running the code with React 19.3.1 and React Testing Library.
Every question is free to read. Sign in with Google to see the answers: the short version to say in the interview, why it's true, and what they'll ask next.
147 of 147 questions
Rendering & JSX
- What is the difference between a component and an element?
- What does JSX compile to, and why must a component return a single root?
- Why do lists need keys, and why is the array index a poor key when items move?
- What does React render for
null,false,undefined,0, and"", and is returningnullthe same as not rendering a component? - What is the difference between rendering and committing? When does React touch the DOM?
- Why should components be pure, and what does Strict Mode's double render catch?
- What does this cart show when it has no items?
- You type a note for Tea and remove Tea. With index keys, what does the list show?
- Two counters switch style: which one keeps its count?
- With Strict Mode on, what does this component log on mount and after one click?
- Render a product list with keys, a Sold out badge, and an empty message
- Write a recursive
CategoryTreethat renders nested categories - Write a
Highlightcomponent that wraps matches of a query in<mark>
Components & props
- What is the difference between props and state, and why are props read-only?
- What is the
childrenprop, and how do you pass JSX into a component? - What is the difference between controlled and uncontrolled inputs, and when do you use each?
- When do you lift state up, and how does composition help you avoid prop drilling?
- What is the difference between a higher-order component, a render prop, and a custom hook?
- Why does defining a component inside another component reset its state on every render?
- What does this page show when a prop with a default is undefined, null, or missing?
- You type Hi into a note box that's defined inside its parent. What does it log and show?
- Which value wins when you spread props and also pass the same prop?
- Build a controlled input with a character count
- Build an accessible
Togglebutton that works controlled or uncontrolled - Build compound
Tabscomponents that share state through context
State & events
- What does this counter log and show when you click Add once?
- What is an updater function, like
setCount((c) => c + 1), and when do you need one instead of a value? - Why must you not mutate state objects and arrays, and how do you update nested state?
- What is batching in React, and did it change in React 18?
- When does setting state re-render a component, and when does React skip it?
- How do you decide what goes in state, and how do you avoid redundant or duplicated state?
- What does "state as a snapshot" mean, and how does it explain stale values in async code?
- What does this profile log and show after you click Rename, then Like?
- What does this counter log when you click Add three times, quickly?
- What does this product card log when you click Add to cart, then Wishlist?
- How many times does this component render when you click Set to 1 three times?
- Build a counter with a step and a reset, using updater functions
- Build a shopping list where you can add, tick off, and remove items without mutating state
Effects
- What are Effects for, and what shouldn't go in an Effect?
- How does the
useEffectdependency array work: no array,[], and[a, b]? - Why does React run Effects twice in development Strict Mode, and how do you write Effects that survive it?
- How do you avoid race conditions when you fetch data in an Effect?
useEffectvsuseLayoutEffect: when does each run, and when do you need the layout one?- What is
useEffectEventfor, and why can't you call an Effect Event during render? - What does this Effect log when the component mounts in Strict Mode?
- What does this chat room log when you switch rooms?
- How many times does this Effect run after two clicks, when its dependency is an object?
- In what order do a parent's and a child's Effects run on mount, and clean up on unmount?
- What does this component log when its layout effect sets state?
- Write a
useDocumentTitlehook that puts the old title back on unmount - Write a
useWindowEventhook that always calls the latest handler without re-subscribing
Hooks & custom hooks
- What are the Rules of Hooks, and why does React need them?
- What makes a function a custom hook, and do components that call it share its state?
- What do
useMemo,useCallback, andmemoeach cache, and when do they help? - When do you use
useRefinstead ofuseState, and why doesn't changing a ref re-render? - When is
useReducera better choice thanuseState? - How does React know which
useStatecall belongs to which piece of state? - What does this ref counter log and show after three clicks?
- Two components call the same custom hook: what do they show after these clicks?
- This
useMemoleaves out a dependency: what does it log and show? - Write a
usePrevioushook - Write a
useTogglehook with a stabletogglefunction - Write a
useDebouncedValuehook - Write a
useLocalStorageStatehook that saves state as JSON
Refs & the DOM
- What are refs for, and when should you not use them?
- How do you focus an input or scroll to an element right after a state change?
- In React 19,
refis a prop. What changed fromforwardRef, and what are ref cleanup functions? - What does
useImperativeHandledo, and when is it justified? - Callback refs vs object refs: when does React call a callback ref, and with what?
- Two callback refs log every call. What does this log when you hide the note and show it again?
- This component reads a ref while it renders. What does the page show after one click?
- Three callback refs, two with cleanups. What does this log when you click Clicked 0, then Toggle?
- Build a
SearchBoxwhose Search button puts the cursor in the field - Build an
AutoGrowListthat scrolls each new item into view - Build a
Modalthat gives the focus back to whatever opened it
Context & state management
- What problem does context solve, and what are its downsides?
- Why do all context consumers re-render when the provider's value changes, and how do you avoid unnecessary renders?
- When would you reach for an external store like Zustand or Redux instead of context, and where does
useSyncExternalStorefit? - How do you structure state and dispatch with a reducer and context in a medium-sized app?
- What is tearing, and how does
useSyncExternalStoreprevent it? - What does this page show when some readers have no provider above them?
- The provider's value is a new object on every render. Does a memoized reader render again?
- With nested providers, which theme does each component read?
- Which components render again when the theme provider's state changes?
- Write a
ThemeProviderand auseThemehook that throws a helpful error outside the provider - Write a cart reducer with add, remove, and set quantity, and a
CartProviderto share it - Write a tiny store,
createStore(initial), and auseStore(store, selector)hook onuseSyncExternalStore
Performance
- What causes a React component to re-render?
- When does
memohelp, and why do inline objects and functions break it? - How do you find which component makes a React page slow?
- What is list virtualization, and when do you need it?
- What does the React Compiler do, and does it replace
useMemoanduseCallback? - How do moving state down and passing content as
childrenavoid re-renders withoutmemo? - Two
memobadges, one with an inline style object: what logs when the parent updates twice? - A
useCallbackwith[]dependencies reads state: what does it log after three adds? - A stateful panel renders
childrenand a render prop: which components render when it toggles? - Stop a task list from re-rendering unchanged rows when you filter or tick a task
- Rank a leaderboard only when the players or the sort order change
- Write a
useDeferredSearchhook that keeps old results, marked stale, while new ones render
Suspense, transitions & actions
- What is Suspense, and what can make a component suspend?
useTransitionvsuseDeferredValue: what does each do, and when do you use which?- What are Actions in React 19, and what do
<form action>,useActionState, anduseFormStatusdo? - What does
useOptimisticdo, and what happens to the screen when the action fails? - What is the
useAPI, and why must the promise you pass it be cached? - How do error boundaries work, what don't they catch, and how do you reset one?
- What does this Suspense example log and show after you show, hide, and show the notes again?
- One tea in this menu has no price. What does the page log and show?
- You switch tabs in a transition, and the new tab suspends. What's on screen right after the click, and what does it log?
- Both components call
useFormStatus. Which one sees the form as pending when you press Save? - Write an
ErrorBoundaryclass with a fallback and a Try again button - Write a form with
useActionStatethat shows a pending button and the action's error - Write a list with
useOptimisticthat adds items at once and rolls back when saving fails
Server rendering & Server Components
- What's the difference between client-side rendering, server-side rendering, and static generation?
- What is hydration, and what causes hydration mismatch errors?
- What are React Server Components, and how are they different from server-side rendering?
- What can a Server Component pass as props to a Client Component, and why?
- What are Server Functions (
'use server'), and what security rules apply to them? - How does streaming server rendering with Suspense work?
- Why does React recommend a framework for new apps, and when is a Vite single-page app fine?
- What's new in React 19 for
<title>,<meta>, and stylesheets withprecedence? - What does this component log on the server with
renderToString, and what HTML comes back? - What do these fields show after a re-render, with ids from
useIdand from a counter? - Write a
useHydratedhook
How React works inside
- What is reconciliation, and what assumptions let React do it in linear time?
- What is a fiber, and why did React move to the Fiber architecture?
- Inside React, what do the work loop and the commit phase actually do?
- What are lanes, and how does React decide which updates to render first?
- How does React's event system work? Where are the listeners, and what is a synthetic event?
- What does concurrent rendering mean if JavaScript has only one thread?
- What does React do inside when a component's
keychanges, and why does that reset its state? - Only Counter B's wrapper changes. What does the page log and show after you switch the layout?
- Two lists, one keyed by name and one by index, are reversed. Which rows keep their state, and which
<li>elements does React move? - An async click handler sets state before and after an
await. What does it log and show? - Write a minimal
createElement(type, config, ...children) - Write a tiny
renderElement(element, container)that turns elements into DOM
Patterns, testing & TypeScript
- How do you test a React component the way users use it?
- How do you test a component that fetches data?
- How do you type props, children, events, and refs in React with TypeScript?
- How do you structure a React project as it grows?
- How do you make a custom dropdown accessible?
- Portals: why use them for modals, and how do events bubble through them?
- How would you design a reusable form library API in React?
getByTextorgetByRole: which element does each query find?- A click inside a portal: which handlers run, and in what order?
- Build an accessible
Accordionwitharia-expandedandaria-controls - Build a
Toastthat renders intodocument.bodyand dismisses itself - Write a
useAsync(fn)hook that returns{ status, data, error, run }and ignores stale results