Exersice 1: Simulate componentDidMount
and componentWillUnmount
In App.jsx
, use useEffect
with an empty dependency array to simulate componentDidMount
.
Inside this useEffect
, log a message that says "Dashboard mounted".
Add another useEffect
to simulate componentWillUnmount
by returning a cleanup function that logs "Dashboard unmounted".
Show Solution
Exersice 2: Test Lifecycle Simulation
UserInfo
component on and off and observe the console for mount and unmount messages.useEffect
behaves like componentWillUnmount
.Exersice 3: Simulate componentDidUpdate
useEffect
with specific dependencies (like count
or age
) to simulate componentDidUpdate
.count
or age
updates.
useEffect(() => {
console.log(`Count updated to: ${count}`);
}, [count]);
useEffect(() => {
console.log(`Age updated to: ${user.age}`);
}, [user.age]);