React Interview Questions and Answers
38 React interview questions with clear answers and code: rendering, hooks, state management, performance, Server Components, testing and senior-level architecture.
Key takeaways
- React interviews test how rendering and state work, not memorized API names.
- Expect questions on hooks and effects in every interview, at every level.
- Mid-level candidates are judged on performance and state architecture; seniors on trade-offs such as server vs client rendering.
- Most interviews include a live component exercise: a list with search, loading and error states.
Contents
React interviews test how well you understand rendering and state, not whether you remember API names. Below are 38 questions that frontend interviewers ask most often, grouped by topic and marked by level, with concise answers and code where it helps.
What React interviews cover
Editorial estimate for a mid-level frontend role; senior interviews shift weight toward architecture.
- Hooks and effects30%
- Rendering and reconciliation20%
- State management15%
- Performance15%
- Live coding15%
- Testing and accessibility5%
What changes by level
| Level | What they expect | Typical question |
|---|---|---|
| Junior | Components, props vs state, basic hooks, lists and keys | Why do list items need keys? |
| Mid | Effects without bugs, state architecture, performance basics, testing | How do you find and fix a slow React app? |
| Senior | Trade-offs: rendering strategies, large-scale state, design systems, mentoring | How would you structure state in a large application? |
If you are also preparing for JavaScript fundamentals, see our JavaScript interview questions; for the full frontend loop, see frontend interview questions and our coding interview tips.
Fundamentals
1What is React, and what problem does it solve?
JuniorReact is a library for building user interfaces from components. You describe what the UI should look like for a given state, and React updates the DOM when the state changes. This declarative model replaces manual DOM manipulation, which becomes error-prone as an interface grows.
2What is JSX?
JuniorJSX is a syntax extension that lets you write markup inside JavaScript. It compiles to function calls that create React elements:
const el = <h1 className="title">Hello</h1>;
// compiles to roughly:
const el = jsx("h1", { className: "title", children: "Hello" });
Because it is JavaScript, you use className instead of class and embed expressions with {}.
3What is the difference between props and state?
JuniorProps are inputs passed from a parent; a component should treat them as read-only. State is data a component owns and can change over time with a setter. When either changes, the component re-renders. A common rule: if a value can be computed from props or other state, don’t store it in state.
4What triggers a re-render in React?
JuniorA component re-renders when its state changes, when its parent re-renders, or when a context it reads changes. Re-rendering means React calls the component again and compares the result with the previous output; the real DOM is updated only where something changed.
5Why do list items need keys?
JuniorKeys tell React which items are the same between renders. With stable keys (such as database IDs), React can reorder, insert or remove items efficiently and keep each item’s state attached to the right element. Using array indexes as keys breaks this when the list can be reordered or filtered.
6What is reconciliation?
MidReconciliation is the process React uses to compare the new element tree with the previous one and decide what to update. It assumes that elements of different types produce different trees (so they are replaced), and uses keys to match children in lists. This keeps the diff fast enough to run on every render.
7Controlled vs uncontrolled components?
JuniorA controlled input gets its value from React state and updates through onChange. An uncontrolled input keeps its own value in the DOM, which you read through a ref. Controlled inputs make validation and conditional logic easier; uncontrolled ones can be simpler for large forms, often with a form library.
Hooks
8What are the rules of hooks?
JuniorCall hooks only at the top level of a component or custom hook, never inside conditions, loops or nested functions, and only from React functions. React relies on the call order to match each hook with its stored state between renders.
9How does useState work, and why might a state update look delayed?
JunioruseState returns the current value and a setter. Calling the setter schedules a re-render; the variable in the current render does not change. When the next value depends on the previous one, use the updater form:
setCount(c => c + 1); // safe even if called several times in a row
10Explain useEffect and its dependency array.
JunioruseEffect runs side effects after the component renders. The dependency array controls when it runs again: no array means after every render, [] means once after mount, [a, b] means when a or b change. The function it returns is a cleanup that runs before the next effect and on unmount.
useEffect(() => {
const id = setInterval(tick, 1000);
return () => clearInterval(id);
}, []);
11What causes stale closures in hooks, and how do you fix them?
MidEach render creates new functions that capture the values from that render. If an effect or callback keeps an old function, it sees old state. Fixes: include the value in the dependency array, use the updater form of the setter, or store the latest value in a ref when you need it inside a long-lived callback.
12When should you use useMemo and useCallback?
MidUse them to keep an expensive computed value or a function identity stable between renders, mainly when it is passed to a memoized child or used as an effect dependency. They are not free: wrapping everything adds overhead and noise. Measure first, then memoize where it removes real work.
13useRef vs useState?
MidBoth persist across renders, but changing a ref does not trigger a re-render. Use refs for DOM nodes and for mutable values that the UI doesn’t display, such as timer IDs or the latest callback. Use state for anything that should update what the user sees.
14useState vs useReducer?
MiduseState suits simple, independent values. useReducer centralizes complex transitions in a pure function, which helps when the next state depends on several values or many actions update the same state. Reducers are also easy to unit test.
15What is a custom hook? Give an example.
MidA custom hook is a function starting with use that combines other hooks to share stateful logic without changing the component tree:
function useDebounced(value, delay = 300) {
const [v, setV] = useState(value);
useEffect(() => {
const id = setTimeout(() => setV(value), delay);
return () => clearTimeout(id);
}, [value, delay]);
return v;
}
16useEffect vs useLayoutEffect?
MiduseEffect runs after the browser paints. useLayoutEffect runs after DOM updates but before paint, so you can measure layout and adjust without a visible flicker. Use it sparingly, since it blocks painting.
17Why do effects run twice in development with Strict Mode?
SeniorIn development, Strict Mode mounts, unmounts and mounts components again to surface effects that lack proper cleanup. If your effect breaks when run twice, it will likely break in production too, for example when a component remounts. The fix is a correct cleanup, not disabling Strict Mode.
Get React answer points in real time during your interview
Sottena listens to the interviewer, detects each question and shows short answer points in about a second. 150 free credits, no card required.
State management
18What does lifting state up mean?
JuniorWhen two components need the same data, you move the state to their closest common parent and pass it down as props, with callbacks to update it. This keeps a single source of truth.
19When is Context the right tool, and when is it not?
MidContext is good for values many components read but that change rarely: theme, locale, the current user. Every consumer re-renders when the context value changes, so it is a poor fit for frequently updated state such as form input or real-time data. Splitting contexts or using a store helps in those cases.
20How do you choose between local state, a global store and a server cache?
MidKeep state as local as possible. Use a store (Redux Toolkit, Zustand, Jotai) for client state shared across distant parts of the app. Treat data from the API as server state and manage it with a cache like TanStack Query or SWR, which handles loading, caching, refetching and invalidation for you.
21How do you avoid prop drilling?
MidFirst check whether component composition solves it: pass components as children so intermediate layers don’t need the data. If not, use context for rarely changing values or a store for shared state. Some prop passing is fine; it keeps data flow explicit.
22How would you structure state in a large React application?
SeniorSeparate server state (in a query cache), global client state (in a small store or a few contexts), URL state (filters, pagination in the query string) and local UI state (in components). Co-locate state with the feature that owns it, derive values instead of duplicating them, and keep side effects at the edges.
Performance
23How do you find and fix a slow React app?
MidMeasure first with the React DevTools Profiler and the browser performance panel. Common fixes: move state down so fewer components re-render, memoize expensive children with memo and stable props, virtualize long lists, split code with lazy, and avoid heavy computation during render.
24What does React.memo do?
MidIt skips re-rendering a component when its props are shallowly equal to the previous ones. It only helps if the props really stay equal, which often requires stable callbacks and memoized objects from the parent.
25How does code splitting work in React?
MidReact.lazy loads a component’s code only when it is first rendered, and Suspense shows a fallback while it loads:
const Settings = lazy(() => import("./Settings"));
<Suspense fallback={<Spinner />}><Settings /></Suspense>
Route-level splitting gives the biggest wins.
26What are concurrent features like useTransition?
SeniorConcurrent rendering lets React interrupt rendering to keep the UI responsive. useTransition marks an update as non-urgent, so typing stays fast while a large list re-renders in the background. useDeferredValue does something similar for a value.
27How do you render a list of 50,000 rows?
SeniorVirtualize it: render only the rows visible in the viewport plus a small buffer, with a library such as TanStack Virtual or react-window. Combine it with stable keys, memoized rows and, if needed, pagination or server-side filtering.
Rendering and architecture
28CSR vs SSR vs SSG: what’s the difference?
MidClient-side rendering sends JavaScript that builds the page in the browser. Server-side rendering generates HTML per request, which improves first paint and SEO. Static generation builds HTML at build time for content that rarely changes. Frameworks like Next.js mix all three per route.
29What are React Server Components?
SeniorComponents that run only on the server and send a serialized result to the client, so their code and dependencies never reach the browser. They can read data directly but cannot use state or effects. Interactive parts are client components, marked with "use client".
30What is hydration, and what causes hydration errors?
SeniorHydration attaches React’s event handlers and state to server-rendered HTML. Errors occur when the client’s first render produces different markup than the server’s, for example from using Date.now(), random values or browser-only APIs during render. Move such logic into effects or make it deterministic.
31What are error boundaries?
MidComponents that catch rendering errors in their subtree and show a fallback UI instead of crashing the whole app. They don’t catch errors in event handlers or async code, which you handle with try/catch.
32What are portals used for?
MidcreatePortal renders children into a different DOM node, such as document.body, while keeping them in the same React tree. They are used for modals, tooltips and dropdowns that must escape parent overflow or z-index rules.
Testing and quality
33How do you test React components?
MidWith React Testing Library and a runner like Vitest or Jest, test behavior the way a user sees it: find elements by role or label, interact with them and check the result. Avoid testing implementation details such as internal state. Use end-to-end tests (Playwright, Cypress) for critical flows.
34How do you make a React app accessible?
MidUse semantic HTML first (button, label, headings), keep focus visible and managed in modals, provide text alternatives, and ensure everything works with a keyboard. Test with a screen reader and automated tools such as axe.
35Why use TypeScript with React?
JuniorTyped props and state catch mistakes at compile time, make components self-documenting and make refactoring much safer. It also improves editor autocomplete for hooks and event handlers.
Live coding exercises
36Build a search box that filters a list fetched from an API.
MidWhat interviewers look for: debounced input, loading and error states, cancelling outdated requests and accessible markup.
function Search() {
const [q, setQ] = useState("");
const query = useDebounced(q, 300);
const [state, setState] = useState({ status: "idle", items: [] });
useEffect(() => {
if (!query) return setState({ status: "idle", items: [] });
const ctrl = new AbortController();
setState(s => ({ ...s, status: "loading" }));
fetch(`/api/items?q=${encodeURIComponent(query)}`, { signal: ctrl.signal })
.then(r => r.json())
.then(items => setState({ status: "done", items }))
.catch(e => e.name !== "AbortError" && setState({ status: "error", items: [] }));
return () => ctrl.abort();
}, [query]);
// render input with a <label>, a spinner, an error message and the list
}
37Implement a counter that increments every second and can be paused.
MidKeep the running flag in state, start an interval in an effect that depends on it, and clear the interval in the cleanup. Use the updater form setCount(c => c + 1) so the interval never reads stale state.
38Design a reusable form component library. What would you consider?
SeniorControlled vs uncontrolled inputs (and performance for large forms), validation (schema-based, such as Zod), accessibility (labels, error announcements), composition (<Field>, <Label>, <Error>), integration with form libraries, theming, and how to test it. Explain which trade-offs you would choose for your team’s use case.
How to prepare
- Rebuild the classicsA searchable list, a modal, a multi-step form and an infinite scroll. Time yourself and talk while coding.
- Know your hooks deeplyBe able to explain the dependency array, cleanup, stale closures and when memoization helps.
- Practice debugging out loudTake a component with an unnecessary re-render or a stale state bug and explain how you’d find it with the Profiler.
- Prepare one architecture storyA project where you chose a state management or rendering approach, and why.
- Review testing and accessibilityBe ready to write a React Testing Library test and name basic a11y practices.
Get answer points in real time during your interview
Sottena listens to the interviewer, detects each question and shows short answer points in about a second. 150 free credits, no card required.