React Props: Passing Data Between Components

Day 4 — Props: Passing Data Between Components in React 🚀 In React, Props (short for properties) are how components talk to each other. Think of props like arguments you pass to a function. 🔹 What are Props? Props are read-only inputs to a component They are passed from Parent ➝ Child A child component cannot modify props They make components reusable & predictable 📌 React follows one-way data flow to keep apps easy to debug. 🔹 Simple Real-Life Analogy Imagine a TV remote 📺 The remote (parent) sends commands The TV (child) receives and uses them The TV can’t change the remote That’s exactly how props work. 🔹 Basic Example Parent Component JavaScript function App() { return ( <User name="Prashanth" role="Frontend Developer" /> ); } Child Component function User(props) { return ( <h2> Hi, I’m {props.name} and I work as a {props.role} </h2> ); } ✅ Output: Hi, I’m Prashanth and I work as a Frontend Developer 🔹 Destructuring Props (Cleaner Way) function User({ name, role }) { return <h2>{name} — {role}</h2>; } ✔️ Cleaner ✔️ More readable ✔️ Preferred in real projects 🔹 Props Make Components Reusable ♻️ <User name="Prashanth" role="Angular Developer" /> <User name="Rahul" role="React Developer" /> <User name="Anita" role="UI Designer" /> 👉 Same component 👉 Different data 👉 Zero duplicate code 🔹 Important Rules to Remember ❌ Props are immutable (read-only) ❌ Child should NOT modify props ✅ Use state if data needs to change ✅ Props = data flow ✅ State = data control 🔹 Why Props Matter? Keeps UI predictable Improves component communication Makes apps scalable Encourages clean architecture 🧠 One-Line Summary Props allow data to flow from parent to child, making React components reusable, predictable, and easy to maintain. #React #ReactTips #LearnReact Want Day 5 — State vs Props next? 😄

To view or add a comment, sign in

Explore content categories