React Middle interview questions and answers
75 questions for a React (Middle) interview - with correct answers, explanations and links to the docs.
Take this quiz- 1.When does React preserve a component's state between renders?
- 2.How do you reset the state of
<EditForm />when switching to another user? - 3.What does
React.memo(Component)do? - 4.Why doesn't
memohelp<List items={data} onSelect={() => select(id)} style={{ gap: 8 }} />? - 5.What is
useMemofor? - 6.Why shouldn't you declare a component inside another component?
- 7.How are
useCallback(fn, deps)anduseMemorelated? - 8.When is
useCallbackactually useful? - 9.When is
useReducerpreferable touseState? - 10.How does
useLayoutEffectdiffer fromuseEffect? - 11.Why does the counter stop at 1?
- 12.Why does this effect run after every render?
- 13.How do you avoid a race when loading data in
useEffectifuserIdchanges quickly? - 14.What's the right way to get
fullNamefromfirstNameandlastNamestored in state? - 15.Which errors does an error boundary NOT catch?
- 16.What changed about passing
refto function components in React 19? - 17.How do events behave inside a portal
createPortal(child, document.body)? - 18.What is a higher-order component (HOC)?
- 19.What's the idea of the render props pattern?
- 20.What is the compound components pattern?
- 21.Why do all context consumers re-render on every provider render?
- 22.Why split context into
StateContextandDispatchContext? - 23.What does
useTransitiondo? - 24.When should you use
useDeferredValue? - 25.What is automatic batching in React 18+?
- 26.What is
useIdfor? - 27.What is
useSyncExternalStorefor? - 28.How does React 19's
use(promise)differ from regular hooks? - 29.What does
useActionStategive you in React 19? - 30.What is
useOptimisticfor? - 31.What does the React Compiler do?
- 32.Why is React Hook Form usually faster than forms with controlled fields?
- 33.How do nested
<Suspense>boundaries behave? - 34.Where is code splitting with
lazyusually most beneficial? - 35.What's wrong with this case reducer in
createSlice? - 36.Which actions does
createAsyncThunk('users/fetch', ...)generate? - 37.How does RTK Query know which data to refetch after a mutation?
- 38.What is RTK Query?
- 39.What does
createEntityAdaptergive you? - 40.Why does this selector cause a re-render on any action in the store?
- 41.When is Redux (or Zustand) more appropriate than React Context?
- 42.How does
staleTimediffer fromgcTimein TanStack Query? - 43.Why does TanStack Query, with default settings, refetch data when you return to the tab?
- 44.How do you update a list after successfully creating an item via
useMutation? - 45.Which queries does
invalidateQueries({ queryKey: ['todos'] })invalidate? - 46.How do you implement an optimistic update via the cache in TanStack Query?
- 47.How do you run a query only after
user.idis received from another query? - 48.With pagination, how do you show the old page while the new one loads, instead of a skeleton?
- 49.What does TanStack Query do on a query error by default on the client?
- 50.Why does
useQueryhave aselectoption? - 51.What is wrong with this effect?
- 52.Where should code that runs because the user clicked "Buy" go?
- 53.Why does this chat effect reconnect when the theme changes?
- 54.Why does this effect re-run on every render even though
optionslooks the same? - 55.How should a component subscribe to a browser event like
resize? - 56.What makes a good custom hook?
- 57.How does
forwardRefrelate to React 19? - 58.What does
<Suspense fallback={<Spinner />}>show, and when? - 59.Which state variables are needed here?
- 60.How do you avoid many boolean flags like
isSending,isSent,isErrorat once? - 61.Why is this component impure?
- 62.What happens when a component's state changes but the output JSX is identical?
- 63.What does
setCount(5)do ifcountis already 5? - 64.How do you measure an element's size right after it renders, before the browser paints?
- 65.Why might a list of controlled inputs lose focus on each keystroke?
- 66.What is the
<Profiler>component for? - 67.Why is it fine to call
setStateinsideuseEffectthat depends onuserIdto fetch data? - 68.How does
useFormStatushelp in a React 19 form? - 69.What does
<form action={saveAction}>do in React 19? - 70.What does
Children.maporcloneElementusage usually signal in modern React? - 71.What happens if a parent passes
onChange={() => {}}inline to a memoized child? - 72.When does a
useRefvalue change cause a re-render? - 73.Why shouldn't you read or write
ref.currentduring render? - 74.What is the difference between a controlled and uncontrolled component in a design system?
- 75.Why can
useEffectwith anasynccallback be a problem?