gistlib
import React, { useState, useEffect } from 'react'; const CounterComponent = () => { const [counter, setCounter] = useState(0); useEffect(() => { const interval = setInterval(() => { setCounter(prevCounter => prevCounter + 1); }, 1000); // 1000 milliseconds = 1 second return () => clearInterval(interval); }, []); return <div>{counter}</div>; }; export default CounterComponent; 411 chars18 lines
import React, { useState, useEffect } from 'react'; const CounterComponent = () => { const [counter, setCounter] = useState(0); useEffect(() => { const interval = setInterval(() => { setCounter(prevCounter => prevCounter + 1); }, 1000); // 1000 milliseconds = 1 second return () => clearInterval(interval); }, []); return <div>{counter}</div>; }; export default CounterComponent;
gistlibby LogSnag