Skip to main content
Journey Uncommon Logo
JourneyUncommon
mediumReactcustom hooksSingle-choice MCQ

A custom hook `useEvent` is meant to give a child a stable callback reference that always 'sees' the latest props/state without going stale. A team implements it as shown. What is the subtle correctness problem with calling the returned function during rendering?

function useEvent(handler) { const ref = useRef(handler); useLayoutEffect(() => { ref.current = handler; }); return useCallback((...args) => ref.current(...args), []); }