Sharing state between components
📖 Scenario: You are building a simple React app that shows a counter. The counter value is shared between two components: one to display the count and one to increase it.This is like having a shared scoreboard where one person can see the score and another can update it.
🎯 Goal: Create two React functional components that share the same counter state. One component will show the current count, and the other will have a button to increase the count.
📋 What You'll Learn
Use React functional components
Use the
useState hook to hold the counter valueShare the counter state between two components via props
Update the counter from the increment button component
Display the current counter value in the display component
💡 Why This Matters
🌍 Real World
Sharing state between components is common in React apps, like sharing user info or app settings across different parts of the UI.
💼 Career
Understanding how to share and update state between components is a key skill for React developers building interactive web apps.
Progress0 / 4 steps