Code Room
Vibe codingHardvc-g121
Subject Ai code reviewLevel Senior–Staff~20 minCommon in Networking & APIs interviewsIndustries Software development, Telecom

Question

An AI wrote this React Native chat hook. Messages duplicate more and more as the user navigates in and out of the screen, and the app's memory climbs. Diagnose it.

tsx
function useChat(roomId: string) {  const [msgs, setMsgs] = useState<Msg[]>([]);  useEffect(() => {    const sock = openSocket(roomId);    sock.on('message', m => setMsgs(prev => [...prev, m]));  }, [roomId]);  return msgs;}
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.