Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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]
    );
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #react #count
ADD COMMENT
Topic
Name
9+9 =