Table of Contents
Use these 50 React interview questions to practice explaining how an interface works and how you would debug it. Start with the component and state questions, then work through the examples on effects, routing, and performance.

Components and JSX
1. What is React?
A JavaScript library for building interfaces from components. Routing, data loading, and deployment may be handled by other libraries or a framework.
2. What is JSX?
A syntax extension for describing elements in JavaScript. A build tool transforms it into JavaScript the browser can execute.
3. How do you pass data to a child?
Pass it as props. Treat props as read-only for that render. A parent can pass a new value on a later render.
4. How do children report changes?
The parent passes a callback. The child calls it when an event occurs, and the state owner decides what to update.
5. How do event handlers work?
Pass a function reference such as onClick={handleClick}. Writing onClick={handleClick()} calls the function during render.
6. How do you render a list?
Map an array to elements and give each sibling a stable key from the underlying data.
7. Why are array indexes fragile keys?
After an insertion, deletion, or sort, an index can refer to a different item and React may preserve state for the wrong row.
8. When would you use a Fragment?
To group children without introducing a DOM element. Use the explicit Fragment syntax if the group needs a key.
9. How do conditional elements work?
Use a branch, a ternary, or return null. For a count, use count > 0 before an && expression so React does not render a stray zero.
10. How do function and class components differ?
Function components use Hooks for state and related features. Class components use instance methods and lifecycle APIs and still appear in existing projects.
State and rendering
11. What is state?
State is component memory. A setter queues an update, and React supplies the new state to a later render.
12. Why does a handler see the old state after calling a setter?
Each render and its handlers see a snapshot. A setter does not change the variables already captured by that handler.
13. When should you use a functional state update?
When the next value depends on the previous value, as in setCount(c => c + 1). This also works when React processes multiple queued updates together.
14. How do you update an object or array in state?
Create a new object or array and replace the affected nested values as needed. Mutating the existing object can interfere with change detection and earlier snapshots.
15. What is lifted state?
Move shared state to the closest common owner and pass values and callbacks down to the components that need them.
16. What is a controlled input?
React supplies its value or checked prop and updates state from onChange. A defaultValue prop instead sets the initial value of an uncontrolled input.
17. What is derived data?
Data you can calculate from existing props or state, such as a filtered list. Calculate it during render so it cannot drift from its inputs.
18. How does React preserve or reset state?
React uses the component type and position, including keys, to identify a component. Changing its key resets its state, useful when switching between records in a form.
19. What is the difference between render and commit?
During render, React calls components to compute the desired UI. During commit, it applies changes to the DOM.
20. What does reconciliation do?
React uses identity at each position to determine what it can preserve and what it must replace. Render work does not imply a change to every DOM node.
Hooks and effects
21. What are the Rules of Hooks?
Call ordinary Hooks at the top level of a function component or custom Hook, before conditional returns. React relies on stable call order.
22. What does useEffect do?
It synchronizes a component with something outside React, such as a subscription, timer, or browser API. Put action-specific work in the event handler.
23. What belongs in an effect dependency list?
Include the reactive values the effect reads. Restructure the effect when necessary so those dependencies describe the actual synchronization.
24. When does effect cleanup run?
Before the effect runs again with changed dependencies and when the component unmounts. Use it to detach the previous listener or subscription.
25. Why might an effect run an extra time during development?
Strict Mode can run an extra setup and cleanup cycle to surface missing cleanup. Check the cleanup logic if the effect adds duplicate listeners.
26. What is a stale closure?
A function reads props or state from the render where it was created. Check effect dependencies or use a functional update when earlier values are being captured accidentally.
27. When should you use useRef?
Use a ref for a DOM node or a mutable value that should persist between renders without causing the component to render when it changes.
28. How does useRef compare with createRef?
useRef returns a stable object across renders. createRef creates a fresh object per call and is commonly initialized once on a class instance.
29. What is a custom Hook?
A function starting with use that can compose other Hooks. It shares behavior, while each call has its own state unless it connects to shared state elsewhere.
30. When does useReducer help?
Use it when several related state changes are easier to express as actions and a pure reducer.
Shared state, routing, and data
31. What is prop drilling?
Passing props through components that do not use them. For deeply shared values such as a theme, Context can reduce repetitive wiring.
32. How does Context work?
A provider supplies a value to its subtree. useContext reads the closest matching provider above the component.
33. When would you choose Redux?
Consider it for sizable shared client state that benefits from a predictable action flow and debugging tools. Start with local state for isolated component concerns.
34. How do Redux and React Redux work together?
Redux holds state and applies reducers to dispatched actions. React Redux supplies Provider, useSelector, and useDispatch to connect React components to the store.
35. What does a selector do?
It reads or derives the data a consumer needs. Returning stable values for unchanged inputs can avoid needless work.
36. What does React Router add?
It matches URLs to UI and provides client-side navigation. Be ready to explain nested routes, URL parameters, and back-button behavior.
37. Why can a route work from a link but fail after refresh?
The host receives the URL on refresh. A client-rendered single-page app may need a fallback to its entry page for application routes.
38. How should a component handle an API request?
Represent loading, success, empty data, and errors. Use the framework data loader or a query library when available, and guard against stale responses if fetching in an effect.
39. What does a CORS error mean?
The browser cannot share a cross-origin response with your page under the server’s policy. Check the server configuration and the request’s origin.
40. How does a component library such as MUI fit in?
It provides ready-made interface components. You still own data flow, accessible labels, and the behavior of the forms or screens you assemble.
Performance and debugging
41. How do you investigate a slow screen?
Reproduce the slow interaction and use React DevTools Profiler to see what rendered and how much time it took before applying optimizations.
42. When does memo help?
It can skip some parent-driven renders when props stay equal. A memoized component can still render when its own state or subscribed context changes.
43. How do useMemo and useCallback differ?
useMemo can cache a computed value, while useCallback can preserve a function reference. Use them for measured performance needs.
44. What is code splitting?
Split the application so some JavaScript loads when it is needed. lazy with a Suspense boundary can defer loading a component and show a fallback.
45. What does a transition do?
It marks an update as less urgent, such as updating filtered results while a user types. Keep the input’s own state update immediate.
46. What is concurrent rendering?
React can interrupt or abandon some in-progress render work before committing. Keep render logic pure so it can be run again safely.
47. What do error boundaries catch?
They provide fallback UI for errors in descendants during rendering. Handle ordinary event-handler and asynchronous errors where they occur.
48. What is hydration?
React attaches client behavior to server-rendered HTML. The server output and initial client render need to agree for the same inputs.
49. How would you test a component?
Test what users see and do. For a form, type into labeled inputs, submit, and check the visible result or error message.
50. How would you build a counter?
Use useState for the count and update from the previous value when incrementing or decrementing. The example below shows the JSX and handler wiring.
import { useState } from 'react';
export default function Counter() {
const [count, setCount] = useState(0);
return (
<section>
<p>Count: {count}</p>
<button type="button" onClick={() => setCount(c => c + 1)}>Increment</button>
<button type="button" onClick={() => setCount(0)}>Reset</button>
</section>
);
}Try this component in an existing React project. For more practice, trace when the component renders and what changes during the render and commit phases.
Reader Comments 0
Sign in with email or Google to join the discussion.