React interview questions

State and props, re-renders, useEffect traps, keys, stale closures, memoisation, data fetching and component architecture.

Readiness: 0 of 36 nailed

How to use this page: 1. Read a question2. Type your answer3. Check with AI4. Open the model answer5. Timed drill when you’re 70% ready

Fundamentals

FoundationConcept

What is the difference between state and props?

FoundationPredict the output

The user clicks once. What is logged, and what is count after the render?

const [count, setCount] = useState(0);
function handleClick() {
  setCount(count + 1);
  setCount(count + 1);
  console.log(count);
}
FoundationConcept

What is the virtual DOM and reconciliation?

Effects

JuniorIt’s broken: why?

Why does this component send requests forever?

function Products({ category }) {
  const [products, setProducts] = useState([]);
  const filters = { category, inStock: true };

  useEffect(() => {
    fetch('/api/products?' + new URLSearchParams(filters))
      .then(r => r.json())
      .then(setProducts);
  }, [filters]);
}
Mid-levelIt’s broken: why?

A user types fast in a search box and sometimes sees results for an older query. Why?

useEffect(() => {
  const controller = new AbortController();
  fetch('/api/search?q=' + encodeURIComponent(query), { signal: controller.signal })
    .then(r => r.json())
    .then(setResults)
    .catch(err => { if (err.name !== 'AbortError') setError(err); });
  return () => controller.abort();   // cleanup cancels the old request
}, [query]);
Mid-levelIt’s broken: why?

In development, your effect runs twice and the API is called twice. Is that a bug?

Mid-levelConcept

useEffect vs useLayoutEffect?

Rendering

JuniorIt’s broken: why?

Why is using the array index as key a problem? When does it bug out?

Mid-levelConcept

What is the difference between the render phase and the commit phase?

Mid-levelConcept

What does Suspense do?

SeniorConcept

What are useTransition and useDeferredValue for?

JuniorConcept

What is a portal and when do you use one?

Mid-levelReal-world scenario

How can you reset a component’s state when a prop changes, without an effect?

Performance

Mid-levelConcept

When does a component re-render, and how do memo, useMemo and useCallback help?

Mid-levelIt’s broken: why?

Every component using a Context re-renders whenever anything in it changes. How do you fix it?

Mid-levelConcept

What does the React Compiler do?

Mid-levelIt’s broken: why?

A list of 10,000 rows makes the page slow. What do you do?

Forms

JuniorConcept

What is the difference between controlled and uncontrolled inputs?

Mid-levelConcept

What are Actions in React 19, and what do useActionState and useOptimistic do?

JuniorReal-world scenario

How would you build a large form with validation?

State management

Mid-levelReal-world scenario

When would you use Context, Redux/Zustand, or a server-state library?

FoundationReal-world scenario

Two sibling components need to share the same data. How do you handle it?

JuniorConcept

What is prop drilling, and how do you avoid it?

JuniorIt’s broken: why?

What’s wrong with storing fullName in state and syncing it with an effect from firstName and lastName?

Hooks

Mid-levelWrite it by hand

Write a useLocalStorage custom hook.

FoundationConcept

What are the Rules of Hooks, and why do they exist?

JuniorConcept

What is useRef used for, besides DOM elements?

Mid-levelIt’s broken: why?

Why does this counter always log 0 and never increase past 1?

function Counter() {
  const [count, setCount] = useState(0);
  useEffect(() => {
    const id = setInterval(() => {
      console.log(count);
      setCount(count + 1);
    }, 1000);
    return () => clearInterval(id);
  }, []);
  return <p>{count}</p>;
}
Mid-levelConcept

Higher-order components vs custom hooks?

Architecture

SeniorReal-world scenario

How would you structure a large React application?

Mid-levelConcept

What do error boundaries catch, and what don’t they catch?

Server Components

Mid-levelReal-world scenario

How do you decide where the server/client boundary goes with Server Components?

Mid-levelConcept

Are Server Components the same as server-side rendering?

Testing

JuniorConcept

How do you test React components?

Data

JuniorReal-world scenario

What are the options for fetching data in React today?

Accessibility

Mid-levelReal-world scenario

How do you make a React app accessible?

Also prepare