Search code examples
javascriptreactjsswitch-statementframer-motion

I want to change a state via switch function but it doesn't work


I'm trying to change a state from a useEffect and I'm using useScroll from framer motion to trace my y axis position on the webpage, then change a state based on that. As you can see I wrote some codes to make some other states true or false but when I want to change a state with a switch in the same useEffect and with same logic, it doesn't work.

useEffect(() => {
        return scrollY.onChange((latest) => {
            latest > 50 ? setScrollMoved(true) : setScrollMoved(false);
            latest > 399 ? setDevelopmentShow(true) : setDevelopmentShow(false);
            latest > 999 ? setBrandingShow(true) : setBrandingShow(false);
            latest > 1599 ? setDesignShow(true) : setDesignShow(false);
            switch (latest) {
                case latest > 399:
                    setLine("develop");
                case 1599 > latest > 399:
                    setLine("brand");
                case 2100 > latest > 1599:
                    setLine("brand");
            }
        });
    }, []);

Solution

  • I just needed to change my syntax a bit and write it with &&.