function Stopwatch() { const [time, setTime] = useState(0); const [isRunning, setIsRunning] = useState(false); const intervalRef = useRef(null); useEffect(() => { if (isRunning) { intervalRef.current = setInterval(() => { setTime(t => t + 1); }, 1000); } return () => { if (intervalRef.current) { clearInterval(intervalRef.current); } }; }, [isRunning]); const start = () => setIsRunning(true); const pause = () => setIsRunning(false); const reset = () => { setIsRunning(false); setTime(0); }; return (

{time} secondes

); }