Code Room
Code reviewHardcr-g392
Subject Memory leak listenersLevel Senior–Staff~22 minCommon in Code quality & review interviewsIndustries Software development

Question

Review this React TypeScript scroll hook.

What a strong answer looks like

Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix — specific and kind.

Talk through your review
Code to reviewtsx
function useScrollDirection() {  const [dir, setDir] = useState<'up' | 'down'>('up');  const last = useRef(0);   useEffect(() => {    const onScroll = () => {      const y = window.scrollY;      setDir(y > last.current ? 'down' : 'up');      last.current = y;    };    window.addEventListener('scroll', onScroll, { passive: true });    return () => window.removeEventListener('scroll', onScroll);  }, []);   return dir;}
Run or narrate your approach, then ask the coach.