Using Default Props in React Functional Components
📖 Scenario: You are building a simple React app that shows a greeting message. Sometimes the user name is not provided, so you want to show a default name instead.
🎯 Goal: Create a React functional component called Greeting that shows a message with a name prop. Use default props to show Guest if no name is given.
📋 What You'll Learn
Create a functional component named
Greeting that accepts a name propSet default props so that
name is Guest if not providedRender a
<div> with the text Hello, {name}!Use the component twice: once with a
name prop and once without💡 Why This Matters
🌍 Real World
Default props help keep React components flexible and user-friendly by providing fallback values when some data is missing.
💼 Career
Knowing how to use default props is essential for building robust React components that handle missing or optional data gracefully.
Progress0 / 4 steps