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

Function Clock

04React/Day05/vite-project/src/Clock.jsx:3–36  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1import { useEffect, useState } from "react";
2
3function Clock(){
4
5
6 const [time,setTime] = useState(new Date().toLocaleTimeString());
7 const [show,setShow] = useState(true);
8
9 useEffect(()=>{
10
11 if(!show)
12 return;
13
14 const intervalId = setInterval(()=>{
15 setTime(new Date().toLocaleTimeString());
16 console.log("Hi");
17 },1000)
18
19 return ()=>{
20 clearInterval(intervalId);
21 }
22
23 },[show])
24
25
26
27
28 return (
29 <>
30 <button onClick={()=>setShow(!show)}>{show?"hide":"show"}</button>
31 {
32 show&&<h1>Current Time: {time}</h1>
33 }
34 </>
35 )
36}
37
38export default Clock;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected