Interview questions and cheat sheets
React Interview Questions and Answers
This page covers sixteen React interview questions in three groups: fundamentals, hooks and performance, and advanced topics. Each answer explains the reasoning and, where it helps, shows a short example.
By CodingMarble · Published · 5 min read

What interviewers look for
Good React answers explain trade-offs. Saying that useMemo improves performance is weaker than saying when it does and when it only adds noise. The answers below aim for that level, and they assume function components and hooks, which is how current React code is written.
Fundamentals
1. What is the difference between props and state?
Props are inputs passed from a parent and are read-only inside the receiving component. State is data a component owns and can change with its setter, and changing it schedules a re-render. If a value can be computed from props or other state, do not store it as state; compute it during render.
2. Why do lists need keys, and why is the array index a poor key?
Keys let React match items between renders so it can reuse the right component instances. With index keys, inserting or reordering items makes React pair old state with the wrong row, which shows up as inputs keeping stale text. Use a stable id from your data. Index keys are acceptable only for static lists that never reorder.
3. What is the difference between controlled and uncontrolled inputs?
A controlled input takes its value from state and updates it in onChange, so React is the single source of truth and you can validate on every keystroke. An uncontrolled input keeps its value in the DOM and you read it through a ref or from FormData on submit. Uncontrolled inputs are simpler for forms that only need values at submission.
function NameField() {
const [name, setName] = useState("");
return <input value={name} onChange={(e) => setName(e.target.value)} />;
}4. What does lifting state up mean?
When two components need the same data, you move the state to their closest common parent and pass it down as props, along with callbacks to change it. It keeps one source of truth. If lifting means passing props through many layers, consider composition (passing children) before reaching for context.
5. What is reconciliation?
On each render React builds a new tree of elements and compares it with the previous one. Elements of the same type at the same position are updated in place; a different type, or a different key, causes the old subtree to be unmounted and a new one mounted. This is why defining a component inside another component is a bug: each render creates a new type and resets its state.
Hooks and effects
Hooks let function components hold state and run side effects. Their two rules are to call them only at the top level of a component or hook, never inside conditions or loops, and only from React functions. React tracks hooks by call order, so a conditional call corrupts which state belongs to which hook.
6. How does the useEffect dependency array work?
After render, React runs the effect if any value in the array differs from the previous render, compared with Object.is. An empty array runs it once after mount; omitting the array runs it after every render. Every reactive value the effect reads, such as props, state and functions defined in the component, belongs in the array, and the lint rule exhaustive-deps checks this for you.
7. Why does an effect need cleanup?
The function returned from an effect runs before the next run of that effect and when the component unmounts. Use it to undo what the effect set up: remove event listeners, clear timers, abort a fetch, close a socket. Without it, listeners and requests pile up.
useEffect(() => {
const controller = new AbortController();
fetch("/api/items?q=" + query, { signal: controller.signal })
.then((r) => r.json())
.then(setItems)
.catch((e) => { if (e.name !== "AbortError") throw e; });
return () => controller.abort();
}, [query]);8. When is an effect the wrong tool?
Effects are for synchronising with something outside React, such as the network or a browser API. They are the wrong place to derive data from props, to respond to a click (use the event handler), or to reset state when a prop changes (use a key on the component). Extra effects usually cause an extra render and a flash of stale content.
9. What is a stale closure?
A function created in one render captures the state and props of that render. If an effect or timer is set up once with an empty dependency array, it keeps reading the old values forever. Fix it by listing the dependencies, by using the functional update form such as setCount(c => c + 1), or by keeping the latest value in a ref.
10. When should you use useMemo and useCallback, and when not?
They cache a value or a function between renders and are only useful in two cases: the calculation is genuinely expensive, or the result is passed to a memoised child or used as another hook's dependency, where a stable identity prevents extra work. Wrapping every value adds comparison cost and clutter without a measurable gain. Measure with the React Profiler first, and remember that memoisation is only a performance hint, and React may discard cached values.
11. What is a custom hook?
It is a function whose name starts with use and that calls other hooks, so you can reuse stateful logic without reusing UI. A useDebouncedValue or useLocalStorage hook is a typical example. Each component that calls the hook gets its own separate state; hooks share logic, not data.
Context and error handling
12. What is the re-render cost of context?
Every component that reads a context re-renders when the provider's value changes, even if it uses only part of it. A provider that creates a new object each render therefore re-renders all consumers. Keep context for slowly changing data such as theme or the signed-in user, split unrelated values into separate contexts, and memoise the value object.
13. What is an error boundary?
It is a class component with getDerivedStateFromError or componentDidCatch that catches errors thrown while rendering its children and shows a fallback instead of unmounting the whole app. It does not catch errors in event handlers, asynchronous code or server rendering. Most projects use a small library wrapper rather than writing the class by hand.
Server components and state updates
14. What is the difference between server and client components?
Server components render on the server, can read data directly, and send no component JavaScript to the browser, but they cannot use state, effects or browser APIs. Client components, marked with the use client directive, hydrate in the browser and handle interactivity. Keep the client boundary as low in the tree as possible so most of the page stays on the server.
15. Why can state updates look delayed, and how does batching work?
Calling a setter does not change the variable in the current render; it queues a new render. React batches several updates from one event into a single render. If the next value depends on the previous one, pass a function, because setCount(count + 1) twice in a row adds one, while setCount(c => c + 1) twice adds two.
16. Why do effects run twice in development?
In Strict Mode, React deliberately mounts, unmounts and remounts a component in development to expose effects that lack cleanup. It does not happen in production builds. If doubled behaviour breaks your page, the effect is missing a cleanup, not hiding a React bug.
When you answer, name the trade-off in one sentence. That habit separates a memorised answer from an experienced one.
Keep reading
- Interview questions and cheat sheetsJavaScript Interview Questions and AnswersThis page gives you eighteen JavaScript interview questions, grouped from fundamentals to trick questions, each with a precise answer you can say aloud in under a minute. Code examples are short enough to rewrite on a whiteboard.
- Web developmentReact Server Components Explained with ExamplesReact Server Components render on the server and send finished output to the browser, so they can read data directly and add no JavaScript to the page. Make a component a client component only when it needs state, effects or browser events, and keep that boundary as low in the tree as you can.
- Web developmentHow to Speed Up a Next.js WebsiteMost slow Next.js sites are slow for ordinary reasons: oversized images, late-loading fonts, too much client-side JavaScript and uncached data. Fix those four in order, and measure with both Lighthouse and real-user data so you know the change helped.
- Web developmentReact vs Flutter: Which Should You Choose for a New App?Choose React (with React Native for phones) when you already have or need a website and want one JavaScript or TypeScript team across both. Choose Flutter when the app itself is the product, the interface must look identical on every device, and a website is secondary.
Need this built properly for your business?
CodingMarble is a remote studio in India that builds websites, apps and games on fixed packages with the scope written down before payment. Try the free tools we run, or start a project when you are ready.