The 15 React Interview Questions That Actually Come Up (With Answers)
Iโve conducted over 50 React interviews. These are the questions that actually come up โ not obscure trivia, but the questions that separate candidates who use React from candidates who understand React. Youโll also want to be solid on JavaScript fundamentals since React interviews often test both.
1. Whatโs the difference between state and props?
Props are passed from parent to child (read-only). State is managed within a component (mutable via setState/useState). Props flow down, state is local.
The follow-up theyโre really asking: โDo you understand one-way data flow?โ
2. Why do hooks have rules (and what are they)?
- Only call hooks at the top level (not inside loops, conditions, or nested functions)
- Only call hooks from React functions (not regular JS functions)
Why: React relies on the order hooks are called to match state to the correct hook. Conditional hooks break this ordering.
// โ Breaks hook ordering
if (loggedIn) {
const [user, setUser] = useState(null);
}
// โ
Always call, conditionally use
const [user, setUser] = useState(null);
if (loggedIn) { /* use user */ }
3. When does a component re-render?
A component re-renders when:
- Its state changes (setState/useState setter)
- Its parent re-renders (unless wrapped in React.memo)
- A context it consumes changes
Not when props change โ thatโs a common misconception. It re-renders because the parent re-rendered, and the parent passes new props as a side effect.
4. Whatโs the difference between useMemo and useCallback?
useMemomemoizes a value (the result of a computation)useCallbackmemoizes a function (the function reference itself)
const expensiveValue = useMemo(() => computeExpensive(data), [data]);
const handleClick = useCallback(() => doSomething(id), [id]);
useCallback(fn, deps) is equivalent to useMemo(() => fn, deps).
5. How do you prevent unnecessary re-renders?
- React.memo โ skip re-render if props havenโt changed
- useMemo/useCallback โ stabilize values/functions passed as props
- Move state down โ keep state in the lowest component that needs it
- Split components โ isolate frequently-changing state into smaller components
6. Whatโs the virtual DOM and why does React use it?
The virtual DOM is a lightweight JavaScript representation of the real DOM. When state changes, React creates a new virtual DOM tree, diffs it against the previous one, and applies only the minimal changes to the real DOM.
Why: Direct DOM manipulation is slow. Batching changes through a virtual DOM is faster for most UI updates. This is one of the key differences when comparing React vs Angular โ Angular uses a different change detection strategy.
7. Explain useEffect cleanup
useEffect(() => {
const subscription = api.subscribe(id);
return () => {
subscription.unsubscribe(); // Cleanup runs before next effect or unmount
};
}, [id]);
Cleanup runs: (1) before the effect re-runs with new dependencies, and (2) when the component unmounts. It prevents memory leaks from subscriptions, timers, and event listeners.
8. Whatโs the difference between controlled and uncontrolled components?
Controlled: React state drives the input value. Every keystroke triggers setState.
<input value={name} onChange={e => setName(e.target.value)} />
Uncontrolled: The DOM manages the input value. You read it with a ref when needed.
<input ref={inputRef} defaultValue="initial" />
Use controlled for forms that need validation or dynamic behavior. Use uncontrolled for simple forms where you only need the value on submit.
9. How do you share state between components that arenโt parent-child?
- Lift state up โ move state to the nearest common ancestor
- Context API โ for global-ish state (theme, auth, locale)
- State management library โ Zustand, Jotai, or Redux for complex state
- URL state โ for state that should survive page refreshes (search params)
10. What are React Server Components?
Server Components render on the server and send HTML to the client โ no JavaScript bundle for that component. They can directly access databases, file systems, and APIs without an API layer.
Client Components (marked with 'use client') run in the browser and handle interactivity (state, effects, event handlers).
The mental model: Server Components for data fetching and static content. Client Components for interactivity. If youโre new to this paradigm, our What is Next.js guide covers the full picture.
11. How do you handle errors in React?
Error Boundaries catch rendering errors in child components:
class ErrorBoundary extends React.Component {
state = { hasError: false };
static getDerivedStateFromError() { return { hasError: true }; }
render() {
if (this.state.hasError) return <h1>Something went wrong.</h1>;
return this.props.children;
}
}
Error boundaries donโt catch errors in event handlers, async code, or server-side rendering. For those, use try/catch.
12. Whatโs the key prop and why does it matter?
Keys help React identify which items in a list changed, were added, or removed. Without stable keys, React re-renders the entire list on every change.
// โ Index as key โ breaks when list order changes
{items.map((item, i) => <Item key={i} />)}
// โ
Stable unique ID
{items.map(item => <Item key={item.id} />)}
13. How do you optimize a large list?
Use virtualization โ only render the items visible in the viewport:
import { FixedSizeList } from 'react-window';
<FixedSizeList height={600} itemCount={10000} itemSize={50}>
{({ index, style }) => <div style={style}>{items[index].name}</div>}
</FixedSizeList>
Libraries: react-window (lightweight) or react-virtuoso (more features).
14. Whatโs Suspense and how does it work?
Suspense lets you show a fallback while waiting for async content:
<Suspense fallback={<Spinner />}>
<LazyComponent />
</Suspense>
Works with: React.lazy() for code splitting, Server Components for data fetching, and libraries that integrate with Suspense (like Relay or SWR).
15. Describe a React performance issue youโve debugged
This is the question that separates real experience from tutorial knowledge. Have a real story ready:
- โWe had a dashboard with 50 charts re-rendering on every filter change. I used React DevTools Profiler to find that the context provider was at the root, causing everything to re-render. I split the context into separate providers for filters vs. data, reducing re-renders by 80%.โ
The interviewer wants to hear: the problem, how you found it, what you tried, and the result.
FAQ
What React questions are asked in senior interviews?
Senior React interviews focus on performance optimization, state management architecture, Server Components, error boundaries, and real debugging stories. Youโll be asked about re-render prevention, virtualization, context splitting, and when to use external state libraries vs. built-in React state.
Do I need to know hooks for React interviews?
Absolutely. Hooks are the foundation of modern React. You need to understand useState, useEffect (including cleanup), useMemo, useCallback, useRef, and custom hooks. Interviewers expect you to explain the rules of hooks and why they exist, not just how to use them.
Should I learn Next.js for React interviews?
If the company uses Next.js, yes. Even if they donโt, understanding Server Components and the app router shows youโre current with the React ecosystem. Many senior React roles in 2026 expect familiarity with a meta-framework like Next.js or Remix.
How do I prepare for React interviews?
Build something non-trivial that uses hooks, context, error boundaries, and performance optimization. Be ready to explain re-render behavior, the virtual DOM diffing algorithm, and controlled vs. uncontrolled components. Use React DevTools Profiler on your own projects to practice identifying performance issues.
Related: JavaScript Interview Questions ยท TypeScript Interview Questions ยท React Hooks Cheat Sheet