React interviews rarely ask you to build something huge. Far more often, you get a small component that almost works and one question: "What's wrong with this?"

The bugs they pick are not random. They're the ones that show whether you understand how React actually thinks: renders are snapshots, effects need cleaning up, and lists need a way to tell items apart.

Here are three that come up again and again. For each one: the broken code, why it breaks, the quick fix, and the fix an interviewer is really hoping for. You can break and fix all three yourself in the free React Lab.

1. The frozen clock (stale closures)

A counter that should go up every second. It goes to 1, then stops.

function Uptime() { const [seconds, setSeconds] = useState(0); useEffect(() => { const id = setInterval(() => { setSeconds(seconds + 1); }, 1000); return () => clearInterval(id); }, []); return <div>{seconds}s</div>; } 

Why it breaks: the empty dependency array means the effect runs once, on the first render. The interval callback is created at that moment, and it remembers the seconds from that render, which is 0. Every tick, it asks React to set 0 + 1. So it sits at 1 forever.

This is called a stale closure: a function holding on to an old value from an earlier render.

The quick fix is to add seconds to the dependency array. It works, but now the effect tears down the interval and creates a new one every single second.

The fix interviewers want keeps one interval for the life of the component and stops it needing the old value at all:

useEffect(() => { const id = setInterval(() => { setSeconds(prev => prev + 1); }, 1000); return () => clearInterval(id); }, []); 

The updater form, prev => prev + 1, always receives the latest value from React. The callback can be as old as it likes, because it never reads seconds itself.

If you can say "state is a snapshot per render, so the callback closed over the first one", you've answered the follow-up question before they ask it.

Try it: The Frozen Clock

2. The ghost listener (effect cleanup)

A panel that subscribes to updates when it opens. Close it and open it a few times, and the old subscriptions keep running in the background.

function RadarPanel() { const [pings, setPings] = useState(0); useEffect(() => { radar.subscribe(() => { setPings(p => p + 1); }); }, []); return <div>{pings}</div>; } 

In testing with React 19, opening and closing this panel three times left three listeners attached to radar. Each one is still firing and still trying to update a component that's gone.

Why it breaks: subscribe returns a function that unsubscribes. The code throws it away. Nothing ever removes the listener.

The fix is one word: return.

useEffect(() => { const unsubscribe = radar.subscribe(() => { setPings(p => p + 1); }); return unsubscribe; }, []); 

React calls the function an effect returns before the effect runs again and when the component is removed. With the fix, three opens and closes leave zero listeners behind.

The same leak hides in WebSockets, addEventListener, timers and third-party subscriptions. Interviewers like this one because spotting it shows you think about what a component leaves behind, not just what it shows. Bonus point: mention that React's Strict Mode mounts components twice in development on purpose, to surface exactly this kind of missing cleanup.

Try it: The Ghost Listener

3. The shuffled squad (keys in lists)

A list of players, each with a text box for their role. Give Ava the role "Captain", then add a new player to the top. Ava's role jumps to the new player.

{players.map((p, i) => ( <li key={i}> <span>{p.name}</span> <input placeholder="Role" /> </li> ))} 

Tested with React 19: after adding a rookie at the top, Ava's box was empty and the rookie's box said "Captain".

Why it breaks: React uses the key to match list items between renders. With key={i}, the item at the top always has key 0. Before the insert, key 0 was Ava. After it, key 0 is the rookie. React sees "key 0 is still here", keeps that row and its input, and simply changes the name next to it. The typed text stays where it was. The person moves.

The fix is a key that belongs to the item and never changes:

{players.map(p => ( <li key={p.id}> <span>{p.name}</span> <input placeholder="Role" /> </li> ))} 

Now React moves each row with its player, and "Captain" stays with Ava.

Index keys are fine for a list that never reorders, filters or inserts. The moment items can move, use a stable id. And the name isn't good enough either: two players can both be called "Rookie".

Try it: The Shuffled Squad

What these three have in common

None of these bugs throw an error. The app runs, the screen looks almost right, and that's exactly why interviewers use them. They're testing whether you can reason about:

  • Snapshots: each render sees its own values (bug 1).
  • Lifecycles: what your component starts, it must also stop (bug 2).
  • Identity: React needs to know which item is which (bug 3).

When you explain a fix in an interview, say the why in one sentence before you write any code. That's usually the difference between "it works" and "they get it".

Practise them properly

I built a free React Lab with these three and seven more: a button that should add 3 but only adds 1, an effect stuck in an infinite loop, a search that fires on every keystroke, a slow request that overwrites a fast one, and an upvote built with React 19's useOptimistic. Each one is a small broken component you fix in the browser, with hints, XP and a "senior" badge when you use the fix interviewers prefer. It works on a phone.

If you want the full set of questions, answers and a cheat sheet in one place, I also wrote a React interview guide. That's a paid product I made, built around the same labs. The Lab itself is free.

How this post was made: Written by Claude (AI) for Khaya, based on the challenges in Khaya's free React Lab. All six code samples (each bug and each fix) were tested by Claude (AI) with React 19 and jsdom. Not yet tested by Khaya.