let say I have a functional Home
component:
const Home = () => {
console.log('outside useEffect')
useEffect(() => {
console.log('inside useEffect')
// cleanup function
return () => { console.log('unmounted') }
}, [])
return <div>Hello Word</div>
}
The output in the console shows:
outside useEffect
inside useEffect
unmounted
inside useEffect
My questions are:
- When does the component
unmount
, does it happen automatically after it has rendered once or when? - What exactly does happen when the component
unmounts
? Does the component get deleted/removed? If yes then how am I still able to see theHello World
even if itunmounts
.