• 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

    • Toggle the UserInfo component on and off and observe the console for mount and unmount messages.
    • Note how the cleanup function from useEffect behaves like componentWillUnmount.
  • Exersice 3: Simulate componentDidUpdate

    • Use useEffect with specific dependencies (like count or age) to simulate componentDidUpdate.
    • Log a message each time the count or age updates.
    
    useEffect(() => {
      console.log(`Count updated to: ${count}`);
    }, [count]);
    
    useEffect(() => {
      console.log(`Age updated to: ${user.age}`);
    }, [user.age]);