Code Room
Code reviewHard
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.
Learn the concepts
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.