Answers for "react count up every second"

1

react count up every second

const [count, setCount] = React.useState(0);

useEffect(
        () => {
            const timer = () => {
                setCount(count + 1);
            }

            // if you want it to finish at some point
            if (count >= 10) {
                return;
            }
            const id = setInterval(timer, 1000);
            return () => clearInterval(id);
        },
        [count]
    );
Posted by: Guest on March-01-2022

Code answers related to "react count up every second"

Code answers related to "Javascript"

Browse Popular Code Answers by Language