()
| 1 | import React, { useState, useEffect } from 'react'; |
| 2 | |
| 3 | function Exercise7() { |
| 4 | const [count, setCount] = useState(0); |
| 5 | |
| 6 | useEffect(() => { |
| 7 | const id = setInterval(() => { |
| 8 | setCount(prevCount => prevCount + 1); |
| 9 | }, 1000); |
| 10 | |
| 11 | return () => clearInterval(id); |
| 12 | }, []); |
| 13 | |
| 14 | useEffect(() => { |
| 15 | if (count === 5) { |
| 16 | clearInterval(id); |
| 17 | } |
| 18 | }, [count]); |
| 19 | |
| 20 | return <h1>{count}</h1>; |
| 21 | } |
| 22 | |
| 23 | export default Exercise7; |
nothing calls this directly
no outgoing calls
no test coverage detected