0
0
Reactframework~3 mins

Why Passing props to components in React? - Purpose & Use Cases

Choose your learning style9 modes available
The Big Idea

What if you could change one thing and watch it update everywhere instantly?

The Scenario

Imagine you have a webpage with many parts, and you want to show different messages in each part. You try to write the same message again and again inside each section manually.

The Problem

Manually copying and changing content everywhere is slow and easy to mess up. If you want to change the message, you must find and update every spot, which wastes time and causes mistakes.

The Solution

Passing props lets you send data to components like giving them a note to read. Components then show the right message automatically, making your code cleaner and easier to update.

Before vs After
Before
function GreetingAlice() {
  return <div>Hello, Alice!</div>;
}
function GreetingBob() {
  return <div>Hello, Bob!</div>;
}
After
function Greeting(props) {
  return <div>Hello, {props.name}!</div>;
}
<Greeting name="Alice" />
<Greeting name="Bob" />
What It Enables

You can create flexible components that show different content without rewriting code, making your app easier to build and maintain.

Real Life Example

Think of a birthday card template where you just change the name and message for each friend instead of making a new card from scratch every time.

Key Takeaways

Passing props sends data to components to customize their output.

This avoids repeating code and makes updates simple.

It helps build flexible, reusable UI parts.