Software Engineer | 49 questions | 2026
React Interview Questions and Answers
React interview questions for freshers 21
Q1FresherMost askedAnswerHideWhat is React, and why use it?
React is a JavaScript library for building user interfaces from small reusable components. You describe what the UI should look like for a given state. When the state changes, React updates the DOM efficiently.
Why teams use it:
- Declarative, component-based code that is easy to reason about and reuse.
- A virtual DOM and reconciliation that avoid manual DOM updates.
- One-way data flow, which makes bugs easier to trace.
- A large ecosystem (routing, data fetching, testing) and frameworks like Next.js on top.
- The same model for web and mobile (React Native).
React is a library, not a full framework: routing, data fetching and build setup come from other tools.
What they are checking: Whether you can state the core idea beyond 'it is fast'
Q2FresherMost askedAnswerHideWhat is the virtual DOM and how does reconciliation work?
The virtual DOM is a lightweight JavaScript representation of the UI. When state changes, React renders a new tree and compares it with the previous one (diffing). Then it applies only the needed changes to the real DOM.
The diffing rules keep it linear in cost:
- Elements of different types are replaced, and their subtrees are rebuilt.
- Same type: update only changed attributes and recurse into children.
- Lists use
keyto match old and new children.
It is not magic speed: the real benefit is a declarative model with batched, minimal DOM updates. React's Fiber architecture splits rendering into units of work, which allows concurrent features like transitions and Suspense.
What they are checking: Whether you understand diffing and the role of keys
Q3FresherMost askedAnswerHideWhat is the difference between props and state?
Props are inputs passed from a parent to a child; they are read-only inside the child. State is data a component owns and can change over time, and changing it triggers a re-render.
| Props | State | |
|---|---|---|
| Owner | Parent | The component itself |
| Mutable by the component | No | Yes, via setter |
| Purpose | Configure the component | Remember changing data |
- Data flows down through props; events flow up through callback props.
- Do not copy props into state without a reason. The copy can become out of date.
- If two components need the same state, lift it to their closest common parent.
What they are checking: Whether you understand one-way data flow
Q4FresherMost askedAnswerHideHow does useState work, and what is the functional update form?
useState(initial) returns [value, setValue]. Calling the setter schedules a re-render with the new value. State is kept between renders by React, per component instance.
const [count, setCount] = useState(0);
// wrong when updating multiple times from the same value
setCount(count + 1);
setCount(count + 1); // still +1 in total
// right: derive from the latest state
setCount(c => c + 1);
setCount(c => c + 1); // +2
Other points:
- Updates are batched and asynchronous; the variable keeps its old value in the current render.
- Never change objects or arrays directly: create new ones (
setItems([...items, x])). - Pass a function for expensive initial values:
useState(() => compute()). - Setting the same value (by
Object.is) bails out.
What they are checking: Whether you know about batching and out-of-date values
Q5FresherMost askedAnswerHideHow does useEffect work? Explain the dependency array and cleanup.
useEffect runs side effects (fetching, subscriptions, timers, DOM work) after React commits a render.
- No array: runs after every render.
[]: runs once after mount (twice in development with Strict Mode).[a, b]: runs after mount and wheneveraorbchange.- The returned function is cleanup. It runs before the next effect and on unmount.
useEffect(() => {
const id = setInterval(() => setSeconds(s => s + 1), 1000);
return () => clearInterval(id);
}, []);
List every reactive value you use in the array (the lint rule react-hooks/exhaustive-deps helps). Do not use effects for things you can compute during render or in event handlers.
What they are checking: Whether you handle cleanup and dependencies correctly
Q6FresherMost askedAnswerHideWhy are keys needed in lists, and why is using the array index as a key a problem?
Keys let React match items between renders. So it can reorder, add or remove the right elements and keep their state.
{todos.map(t => <TodoItem key={t.id} todo={t} />)}
Index keys are fine for static lists that never reorder. If items can be inserted, deleted or sorted, an index key makes React reuse the wrong component instance. This causes wrong input values, lost focus or old state.
Rules for keys:
- Unique among siblings, stable, and not generated during render (
Math.random()forces a remount every time). - Use a database id or a stable unique field.
- Changing a component's
keydeliberately resets its state.
What they are checking: Whether you understand identity in reconciliation
Q7FresherMost askedFree with sign-inAnswerHideWhat is JSX?
JSX is a syntax extension that lets you write HTML-like markup inside JavaScript. A compiler (Babel, SWC, TypeScript) turns it into function calls (jsx()), producing React elements.
Q8FresherMost askedFree with sign-inAnswerHideWhat is useRef and when would you use it?
useRef(initial) returns a mutable object { current } that stays the same across renders. Changing ref.current does not cause a re-render.
Uses:
- Access a DOM node:
<input ref={inputRef} />theninputRef.current.focus(). - Store values that should not trigger renders (timer ids, previous value, mutable flags).
Q9FresherMost askedFree with sign-inAnswerHideWhat is the Context API and how does useContext work?
Context lets you pass data through the component tree without passing props at every level (avoiding prop drilling). Use it for things like theme, locale or the current user.
Q10FresherMost askedFree with sign-inAnswerHideWhat is the difference between controlled and uncontrolled components?
In a controlled component, React state is the single source of truth for the input value. In an uncontrolled one, the DOM holds the value. You read it with a ref or on submit.
Q11FresherMost askedFree with sign-inAnswerHideWhat does React.memo do, and when is it useful?
React.memo(Component) skips re-rendering a component when its props are shallowly equal to the previous props.
Q12FresherMost askedFree with sign-inAnswerHideWhat are the rules of hooks, and why do they exist?
Two rules:
- Call hooks only at the top level of a component or custom hook: never inside loops, conditions or nested functions.
- Call hooks only from React function components or other hooks.
Q13FresherMost askedFree with sign-inAnswerHideWhat is a custom hook? Write one.
A custom hook is a function whose name starts with use and that calls other hooks. It lets components reuse stateful logic. Each call gets its own independent state.
Q14FresherMost askedFree with sign-inAnswerHideWhy should you not mutate state directly, and how do you update arrays and objects immutably?
React detects changes by comparing references. If you change an object or array directly and pass the same reference to the setter, React sees no change. Memoised children skip updates too, so the UI does not update correctly.
Q15FresherMost askedFree with sign-inAnswerHideWhat does 'lifting state up' mean?
When two or more components need the same changing data, move the state to their closest common parent. Pass it down as props (plus callbacks to update it).
Q16FresherMost askedFree with sign-inAnswerHideWhat is prop drilling and how do you avoid it?
Prop drilling is passing props through several middle components that do not use them, just to reach a deep child. It makes code brittle and noisy.
Q17FresherMost askedFree with sign-inAnswerHideWhat is React Strict Mode, and why do effects run twice in development?
<StrictMode> is a development-only wrapper that highlights problems. In development it renders components twice. Since React 18, it also mounts, unmounts and remounts each component once, to check that effects clean up properly. It has no effect in production.
Q18FresherMost askedFree with sign-inAnswerHideWhat is the difference between class components and function components? Map lifecycle methods to hooks.
Class components use this.state, setState and lifecycle methods. Function components with hooks do the same with less code and easier logic reuse. New code uses function components; classes remain for error boundaries.
Q19FresherMost askedFree with sign-inAnswerHideBuild a countdown timer component in React that counts down from a given number of seconds, with start, pause and reset.
Keep the remaining seconds and a running flag in state. Run a setInterval inside useEffect and clear it on cleanup. Use the functional form of the state setter so the interval never reads an old value.
Q20FresherFree with sign-inAnswerHideWhat are Fragments and Portals?
A Fragment lets a component return several elements without adding an extra DOM node: <>...</> or <Fragment key={id}> when a key is needed.
A Portal renders children into a different DOM node outside the parent's hierarchy. React tree rules still apply: context and event bubbling follow the React tree.
Q21FresherFree with sign-inAnswerHideWhat are synthetic events in React?
Synthetic events are React's cross-browser wrapper around native DOM events. They expose the same interface (target, preventDefault(), stopPropagation()) in every browser.
React interview questions for experienced 18
Q22ExperiencedMost askedAnswerHideWhat is the difference between useMemo and useCallback?
Both memoise a value between renders and only recompute when dependencies change.
useMemo(() => compute(a, b), [a, b])caches a computed value.useCallback(fn, [deps])caches a function; it equalsuseMemo(() => fn, [deps]).
const sorted = useMemo(() => items.slice().sort(cmp), [items]);
const onSelect = useCallback((id) => setSelected(id), []);
Use them when:
- A calculation is genuinely expensive.
- You pass a function or object to a
React.memochild, or use it as a hook dependency, and need a stable reference.
Do not wrap everything: memoisation costs memory and comparison time. Measure with the Profiler first. The React Compiler can add much of this automatically.
What they are checking: Whether you know they are for referential stability and cost, not default habits
Q23ExperiencedMost askedAnswerHideWhat causes a React component to re-render, and how do you reduce unnecessary renders?
A component re-renders when its state changes. It also re-renders when its parent re-renders (even with the same props), or when a context it uses changes.
Ways to reduce it, roughly in order of preference:
- Move state down, closer to where it is used, so fewer components sit under the changing state.
- Pass expensive parts as
childrenor props (composition), so they keep the same element identity. - Split contexts, or use a store with selectors.
- Use
React.memoon heavy children, with stable props throughuseMemoanduseCallback. - Virtualise long lists, and use
useDeferredValueor transitions for expensive updates.
Measure first with React DevTools Profiler ("why did this render") rather than guessing. A re-render alone is cheap; the problem is slow work during it.
What they are checking: Whether you diagnose before optimising
Q24ExperiencedMost askedFree with sign-inAnswerHideWhen would you use Context versus Redux (or another state library)?
Context is a delivery mechanism for a value, not a state manager. Redux (and Zustand, Jotai) provide a store, update patterns and selective subscriptions.
Use Context for low-frequency, app-wide values: theme, locale, auth user, feature flags.
Q25ExperiencedMost askedFree with sign-inAnswerHideWhat are React Server Components, and how do they differ from client components?
Server Components render only on the server (at build time or per request). They send serialised output to the browser, with no component JavaScript shipped for them.
Q26ExperiencedMost askedFree with sign-inAnswerHideWhat is the difference between CSR, SSR, SSG and ISR in Next.js?
- CSR (client-side rendering): the browser downloads JavaScript and builds the page. Slow first paint, weak for SEO without extras.
- SSR (server-side rendering): HTML is generated on each request. Fresh data, good SEO, but needs a server and costs time per request.
- SSG (static site generation): HTML is built once...
Q27ExperiencedMost askedFree with sign-inAnswerHideWhat is new in React 19?
Main additions:
- Actions: functions (often async) passed to
<form action={fn}>or transitions, with built-in pending, error and optimistic handling. useActionStatefor form state from an action,useFormStatusfor pending state inside a form, anduseOptimisticfor instant optimistic UI.use()to read a...
Q28ExperiencedMost askedFree with sign-inAnswerHideWhat are error boundaries and how do you use them?
An error boundary is a component that catches errors thrown while rendering its children, in lifecycle methods and in constructors. It shows a fallback UI instead of crashing the whole app.
Q29ExperiencedMost askedFree with sign-inAnswerHideWhen would you use useReducer instead of useState?
Use useReducer when state has several related fields, when the next state depends on complex rules, or when many different actions update it. It centralises updates in a pure reducer, which is easy to test.
Q30ExperiencedMost askedFree with sign-inAnswerHideWhat is the difference between useEffect and useLayoutEffect?
Both run after React updates the DOM, but at different times.
Q31ExperiencedMost askedFree with sign-inAnswerHideHow do Suspense and lazy loading work?
React.lazy loads a component's code only when it is first rendered. Suspense shows a fallback while the component (or data) is not ready.
Q32ExperiencedMost askedFree with sign-inAnswerHideWhat is useTransition and useDeferredValue?
Both mark updates as non-urgent so React keeps the UI responsive.
useTransitionreturns[isPending, startTransition]. Wrap a state update instartTransitionso React can interrupt it for urgent input.useDeferredValue(value)returns a lagging copy of a value that updates after urgent work finishes.
Q33ExperiencedMost askedFree with sign-inAnswerHideWhat is hydration, and what causes hydration mismatch errors?
Hydration is when React attaches event handlers and state to HTML that the server already rendered. It reuses the existing DOM instead of rebuilding it.
Q34ExperiencedMost askedFree with sign-inAnswerHideHow does React batch state updates?
React groups multiple state updates that happen in the same event or tick into a single re-render. Since React 18 this automatic batching also works inside promises, timeouts and native event handlers, not only React events.
Q35ExperiencedMost askedFree with sign-inAnswerHideWhat are Server Actions in React and Next.js?
Server Actions are async functions marked with "use server". They run on the server but can be called from client code, usually as a form action or from an event handler. The framework creates the network endpoint for you.
Q36ExperiencedMost askedFree with sign-inAnswerHideHow do you build and maintain a shared component library for several React applications?
Treat it as a product: a versioned package with a clear API, documentation and tests, built on shared design tokens.
Q37ExperiencedFree with sign-inAnswerHideHow do you test React components?
Test how a user sees the behaviour, not implementation details.
Q38ExperiencedFree with sign-inAnswerHideWhat is the React Compiler, and does it replace useMemo and useCallback?
The React Compiler is a build-time tool (Babel/SWC plugin). It analyses components and memoises values and functions for you, so you rarely write useMemo, useCallback or React.memo by hand.
Q39ExperiencedFree with sign-inAnswerHideWhat are micro frontends, and when would you use them?
Micro frontends split a large web application into smaller frontends. Separate teams build, test and deploy them independently. They are then combined into one page for the user. It is the frontend version of the microservices idea.
Scenario based React interview questions 10
Q40ExperiencedMost askedScenarioAnswerHideScenario: a page renders a list of 10,000 rows and scrolling and typing feel slow. How do you fix it?
Find the problem first with the React Profiler and the browser Performance tab. Then reduce what is rendered and re-rendered.
- Virtualise (windowing): render only visible rows using
react-window,@tanstack/react-virtualor similar. This is usually the biggest win. - Paginate or filter on the server if users never need all rows at once.
- Stop needless re-renders: stable keys,
React.memoon the row,useCallbackfor handlers, and keep per-row state inside the row. - Move fast-changing state (like a search input) so it does not re-render the list; use
useDeferredValuefor filtering. - Avoid expensive work in render: precompute or memoise sorting and formatting.
- Keep row DOM small and avoid layout thrash.
Confirm with before-and-after measurements.
What they are checking: Whether you measure and reach for virtualisation
Q41ExperiencedMost askedScenarioAnswerHideScenario: your component enters an infinite render loop or you get 'Too many re-renders'. How do you find and fix it?
Causes are usually one of these:
- Calling a setter during render:
<button onClick={setOpen(true)}>runs immediately; it must beonClick={() => setOpen(true)}. - An effect that sets state it also depends on, with no guard:
useEffect(() => { setItems([...items, 1]); }, [items]); // loops forever
- A dependency that is a new object, array or function on every render (
useEffect(fn, [{ a: 1 }])). The effect then re-runs each time and sets state.
Fix:
- Move calculations into render (derived state) instead of effect plus setState.
- Use functional updates (
setItems(prev => ...)) so you do not need the value as a dependency. - Memoise object dependencies with
useMemoor depend on primitives. - Check the call stack and use the lint rule
react-hooks/exhaustive-deps. Add a console log to see which dependency changes.
What they are checking: Whether you can find the loop cause quickly
Q42ExperiencedMost askedScenarioFree with sign-inAnswerHideScenario: a setInterval counter inside useEffect always shows the same old value. Why, and how do you fix it?
This is a stale closure (the callback holds an old value). The effect ran once with []. So the callback captured count from the first render and keeps using it.
Q43ExperiencedMost askedScenarioFree with sign-inAnswerHideScenario: a data-fetching effect shows the wrong user's data when the id changes quickly. How do you fix the race condition?
Responses can arrive out of order, so an older request overwrites the newer one. Cancel or ignore old requests in the effect cleanup.
Q44ExperiencedMost askedScenarioFree with sign-inAnswerHideScenario: design state management for a large React app with auth, a shopping cart, API data and forms.
Split state by type and use the simplest tool for each.
Q45ExperiencedMost askedScenarioFree with sign-inAnswerHideScenario: a content-heavy marketing and blog site must load fast and rank on Google. Which React rendering approach do you choose?
Use a framework with server rendering, most pages as static or incrementally regenerated: Next.js (App Router) or similar.
Q46ExperiencedMost askedScenarioFree with sign-inAnswerHideRefactor a component that calls fetch inside useEffect into a reusable hook that handles loading, error and cancellation.
Move the data logic into a custom hook that returns { data, error, loading }. Use an AbortController so a slow earlier request cannot overwrite a newer one.
Q47ExperiencedMost askedScenarioFree with sign-inAnswerHideScenario: typing in a big form feels laggy because every keystroke re-renders the whole form. What do you do?
Each keystroke updates state at the top, which re-renders everything beneath.
Q48ExperiencedMost askedScenarioFree with sign-inAnswerHideScenario: a child component's state resets unexpectedly (or its input loses focus) on every parent update. What are the likely causes?
React preserves state only while the component keeps the same type at the same position (and key). Resets usually come from:
Q49ExperiencedMost askedScenarioFree with sign-inAnswerHideScenario: how would you handle loading, error and empty states for data fetched on the client?
Treat every request as having four states: loading, error, empty and success, and design each one.