MCPcopy
hub / github.com/facebook/react / useTimer

Function useTimer

fixtures/nesting/src/shared/useTime.js:3–12  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1import {useState, useEffect} from 'react';
2
3export default function useTimer() {
4 const [value, setValue] = useState(() => new Date());
5 useEffect(() => {
6 const id = setInterval(() => {
7 setValue(new Date());
8 }, 1000);
9 return () => clearInterval(id);
10 }, []);
11 return value.toLocaleTimeString();
12}

Callers

nothing calls this directly

Calls 3

useStateFunction · 0.90
useEffectFunction · 0.90
setValueFunction · 0.85

Tested by

no test coverage detected