Ojasa Mirai

Ojasa Mirai

ReactJS

Loading...

Learning Level

🟒 BeginnerπŸ”΅ Advanced
🎁 What are Props?πŸ“€ Passing Props to ComponentsπŸ” Reading Props in Components🎯 Props for Customizationβœ… Prop Types & ValidationπŸ”„ Props vs State⬇️ Passing Functions as PropsπŸš€ Building Reusable Components
Reactjs/Props/What Are Props

🎁 What are Props? β€” The Foundation of Component Communication

Props are how React components communicate with each other. They're the way you pass information from one component to anotherβ€”like function parameters, but for components.


🎯 Understanding Props

Props are properties you pass to a component, like function arguments. They let you customize how a component behaves so you can reuse it in different contexts without duplicating code.

Here's a simple example: imagine you want to display greetings to different users. Instead of creating separate components for each person, you create one component that accepts a name as a prop:

function Greeting({ name }) {
  return <h1>Hello, {name}!</h1>;
}

<Greeting name="Alice" />  // Outputs: Hello, Alice!
<Greeting name="Bob" />    // Outputs: Hello, Bob!

<details>

<summary>πŸ“š More Examples</summary>

// Function parameters work similarly
function greet(name) {
  return `Hello, ${name}!`;
}
greet("Alice");  // Hello, Alice!

// React props use the same concept
function Greeting({ name }) {
  return <h1>Hello, {name}!</h1>;
}
<Greeting name="Alice" />  // Hello, Alice!

</details>

πŸ’‘ Props are Immutable

An important rule: you cannot change props inside a component. Props are read-only. This is a fundamental React principle that keeps your code predictable.

function Card({ title }) {
  // ❌ Wrong - don't do this!
  // title = "New Title";

  // βœ… Correct - just use the prop
  return <div>{title}</div>;
}

🎨 Real-World Example: A Button Component

Instead of creating separate `SaveButton`, `DeleteButton`, and `EditButton` components, you create one reusable Button component that accepts props:

function Button({ text, color }) {
  return <button style={{ background: color }}>{text}</button>;
}

// Now use it many ways without duplicating code
<Button text="Save" color="green" />
<Button text="Delete" color="red" />
<Button text="Edit" color="blue" />

πŸ“Š Props vs State Summary

AspectPropsState
SourcePassed from parentOwned by component
ImmutableYes βœ…Can change βœ…
PurposeCustomize componentStore component data
FlowParent β†’ ChildWithin component

πŸ”‘ Key Takeaways

  • βœ… Props are how you pass data to React components
  • βœ… Props are like function parameters for components
  • βœ… Props are immutableβ€”you cannot change them
  • βœ… Props make components flexible and reusable
  • βœ… Props flow from parent components to child components
  • βœ… Use props to customize component behavior without duplication

Ready to practice? Challenges | Next: Passing Props to Components


Resources

Python Docs

Ojasa Mirai

Master AI-powered development skills through structured learning, real projects, and verified credentials. Whether you're upskilling your team or launching your career, we deliver the skills companies actually need.

Learn Deep β€’ Build Real β€’ Verify Skills β€’ Launch Forward

Courses

PythonFastapiReactJSCloud

Β© 2026 Ojasa Mirai. All rights reserved.

TwitterGitHubLinkedIn