MCPcopy Create free account
hub / github.com/coderarmy-notes/mern-stack-course / App

Function App

04React/Day08/src/App.jsx:6–45  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

4// stopwatch: start, stop, reset
5
6function App() {
7
8 const [time,setTime] = useState(0);
9 const intrervalIdRef = useRef(null);
10
11 function handleStart(){
12
13 if(intrervalIdRef.current!=null){
14 return;
15 }
16
17 intrervalIdRef.current = setInterval(()=>{
18 setTime(time=>time+1);
19 },1000);
20 }
21
22 function handleStop(){
23 clearInterval(intrervalIdRef.current);
24 intrervalIdRef.current = null;
25 }
26
27 function handleReset(){
28 clearInterval(intrervalIdRef.current);
29 intrervalIdRef.current = null;
30 setTime(0);
31 }
32
33
34 return(
35 <>
36 <h1>Stopwatch: {time}</h1>
37 <div>
38 <button onClick={handleStart}>Start</button>
39 <button onClick={handleStop}>Stop</button>
40 <button onClick={handleReset}>Reset</button>
41 </div>
42 </>
43 )
44
45}
46
47export default App

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected