Skip to main content

Command Palette

Search for a command to run...

πŸ”΅ React Props Explained:

πŸ”΅ React Props Explained: The Power of Data Sharing Between Components

Published
β€’3 min readβ€’View as Markdown
πŸ”΅ React Props Explained:

When building applications in React, props play a major role in making components reusable, dynamic, and flexible. They allow you to pass data from one component to another β€” just like arguments to a function.

If you're learning React, understanding props is essential. In this beginner-friendly guide, you’ll learn what props are, why they matter, and how to use them the right way.

βš›οΈ What Are Props in React?

Props (short for properties) are used to send data from a parent component to a child component.

They are read-only, meaning a child component cannot modify the props it receives.

Think of props as:

Inputs that customize how a component behaves or displays content.


🎁 Why Are Props Important?

Props help you:

  • πŸ”Ή Pass dynamic data

  • πŸ”Ή Reuse components in different ways

  • πŸ”Ή Make components flexible and customizable

  • πŸ”Ή Keep your app organized and modular

Without props, your UI would be static and repetitive.


πŸ“¦ How Do Props Work?

1️⃣ Parent component sends data

2️⃣ Child component receives data

3️⃣ Child displays or uses that data


🧩 Example: Passing Props

βœ… Parent Component (App.jsx)

import Welcome from "./Welcome";

function App() {
  return (
    <div>
      <Welcome name="Sagar" />
      <Welcome name="React Developer" />
    </div>
  );
}

export default App;

βœ… Child Component (Welcome.jsx)

function Welcome(props) {
  return <h1>Hello, {props.name} πŸ‘‹</h1>;
}

export default Welcome;

Here’s what happens:

  • The parent passes the value "Sagar" as a prop.

  • The child component displays it.

  • Same component, different outputs β€” thanks to props!


🧠 Destructuring Props

You can simplify your code using destructuring:

function Welcome({ name }) {
  return <h1>Hello, {name} πŸ‘‹</h1>;
}

This makes the component cleaner and easier to read.


πŸ—οΈ Passing Multiple Props

You can pass as many props as you want:

<UserProfile name="Anita" age={22} job="Frontend Developer" />

Child component:

function UserProfile({ name, age, job }) {
  return (
    <div>
      <h2>{name}</h2>
      <p>Age: {age}</p>
      <p>Job: {job}</p>
    </div>
  );
}

πŸ”„ Props vs State

FeaturePropsState
Can be changed?❌ No (read-only)βœ” Yes
Owned byParent componentComponent itself
Used forPassing dataManaging dynamic data

They work together to build powerful, reactive UI.


πŸš€ Props with Functions

Props are not just data β€” you can also pass functions as props!

Parent:

function App() {
  const handleClick = () => alert("Button Clicked!");

  return <Button onClick={handleClick} />;
}

Child:

function Button({ onClick }) {
  return <button onClick={onClick}>Click Me</button>;
}

This is how React handles communication from child β†’ parent.


πŸ”’ Props Are Immutable

One golden rule:

A child must never change its props.

Bad ❌:

props.name = "John";

Good βœ”:

// Use state or callback if you need changes

🎨 Default Props

You can assign default values to props:

function Greeting({ name = "Guest" }) {
  return <h1>Welcome, {name}</h1>;
}

🎯 Conclusion

Props are one of the core building blocks of React, enabling:

βœ” Reusable components
βœ” Clean and structured UI
βœ” Dynamic and flexible layouts
βœ” Smooth parent-to-child data flow

Master props β†’ master component communication β†’ master React.