Lifecycle mapping with hooks
📖 Scenario: You are building a simple React component that tracks and displays the number of times a button is clicked. You want to learn how to use React hooks to map lifecycle events like mounting, updating, and unmounting.
🎯 Goal: Create a React functional component called ClickTracker that uses useState to count clicks and useEffect to log messages when the component mounts, updates, and unmounts.
📋 What You'll Learn
Create a state variable
count initialized to 0Create a
useEffect hook that logs 'Component mounted' once when the component first rendersCreate a
useEffect hook that logs 'Count updated' every time count changesCreate a
useEffect hook that logs 'Component unmounted' when the component is removedRender a button that increments
count when clickedDisplay the current
count value in a <p> element💡 Why This Matters
🌍 Real World
React components often need to run code when they appear, update, or disappear. This project shows how to map those lifecycle events using hooks.
💼 Career
Understanding React lifecycle with hooks is essential for building modern web apps and is a common skill required in frontend developer roles.
Progress0 / 4 steps