Passing props to components
📖 Scenario: You are building a simple React app that shows a greeting message for a user. The greeting text should come from a parent component and be passed down to a child component.
🎯 Goal: Build two React functional components: App and Greeting. Pass a message prop from App to Greeting and display it inside Greeting.
📋 What You'll Learn
Create a functional component called
App.Inside
App, create a variable greetingMessage with the exact string 'Hello, welcome to React!'.Create a functional component called
Greeting that accepts a message prop.Render the
Greeting component inside App and pass greetingMessage as the message prop.Inside
Greeting, display the message prop inside a <h1> element.💡 Why This Matters
🌍 Real World
Passing props is how React components share data, like sending user info or settings from a main app to smaller parts of the UI.
💼 Career
Understanding props is essential for React developers to build reusable and interactive components that work together.
Progress0 / 4 steps