score:3

Accepted answer
const UpdateScrollPosition = useCallback(() => {

    // this now depends on isDesktop
    console.log(isDesktop);

    // .... other code

}, [isDesktop]); // IMPORTANT: add isDesktop here as a dependency

useEffect(() => {
    window.addEventListener("scroll", UpdateScrollPosition);

    return () => window.removeEventListener("scroll", UpdateScrollPosition);
}, [UpdateScrollPosition]); // IMPORTANT: Add UpdateScrollPosition here as a dependency

Related Query

More Query from same tag