Code Room
Vibe codingMediumvc-g249
Subject Ai code reviewLevel Mid–Senior~15 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

An AI wrote this React Native countdown component for a limited-time offer. It works on screen, but after navigating between offers a few times, performance degrades and you see the timer 'tick' firing multiple times per second and warnings about setting state on an unmounted component. What's wrong and how would you fix it?

jsx
function Countdown({ endsAt }) {  const [left, setLeft] = useState(endsAt - Date.now());  useEffect(() => {    setInterval(() => {      setLeft(endsAt - Date.now());    }, 1000);  });  return <Text>{Math.max(0, Math.floor(left / 1000))}s</Text>;}
What a strong answer looks like

Treat the AI’s output as a draft to verify, not an answer to trust. Name the specific flaw and the input that triggers it, say how you’d catch it — tests, edge cases, reading critically — and how you’d re-prompt or decompose to get it right.

Describe your solution

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.