({ color })
| 1 | import React, { useEffect } from 'react' |
| 2 | |
| 3 | const Navbar = ({ color }) => { |
| 4 | // Case 1: Run on every render |
| 5 | useEffect(() => { |
| 6 | alert("Hey I will run on every render") |
| 7 | }) |
| 8 | |
| 9 | // Case 2: Run only on first render |
| 10 | useEffect(() => { |
| 11 | alert("Hey welcome to my page. This is the first render") |
| 12 | }, []) |
| 13 | |
| 14 | // Case 3: Run only when certain values change |
| 15 | useEffect(() => { |
| 16 | alert("Hey I am running because color was changed") |
| 17 | }, [color]) |
| 18 | |
| 19 | // Example of Cleanup function |
| 20 | useEffect(() => { |
| 21 | alert("Hey welcome to my page. This is the first render of app.jsx") |
| 22 | |
| 23 | return () => { |
| 24 | alert("component was unmounted") |
| 25 | } |
| 26 | }, []) |
| 27 | |
| 28 | return ( |
| 29 | <div> |
| 30 | I am navbar of {color} color hehe.. |
| 31 | </div> |
| 32 | ) |
| 33 | } |
| 34 | |
| 35 | export default Navbar |
nothing calls this directly
no outgoing calls
no test coverage detected