()
| 1 | import { useEffect, useState } from "react"; |
| 2 | |
| 3 | function 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 | |
| 38 | export default Clock; |
nothing calls this directly
no outgoing calls
no test coverage detected