Skip to main content
Journey Uncommon Logo
JourneyUncommon
mediumReactuseEffect dependency arraysSingle-choice MCQ

Given this effect, how many times does the cleanup function's log fire across the described lifecycle: initial mount, then two re-renders where `id` changes from 1 to 2 to 2 (unchanged on the third render), then unmount?

useEffect(() => { const sub = subscribe(id); return () => { console.log('cleanup'); sub.unsubscribe(); }; }, [id]);