Why Passing Props Exists
In React:
- Components are isolated
- One component cannot access anotherβs data directly
So how do they communicate?
π Props
What Are Props?
Props are inputs to a component.
Think of them like:
- Function parameters
- API request data
Simple Example
function Greeting({ name }) {
return <h1>Hello {name}</h1>;
}
function App() {
return <Greeting name="John" />;
}
Whatβs Happening?
-
Appsends data βname="John" -
Greetingreceives it β{ name } - UI updates based on props
Backend analogy:
function greeting(name) {
return `Hello ${name}`;
}
greeting("John");
Props Are Read-Only
β This is NOT allowed:
props.name = "Mike";
Props are:
- Immutable
- Owned by the parent
If data must change β it belongs in state, not props.
Common Beginner Mistake
Trying to store everything in one component.
Correct mindset:
Components should receive data, not own everything.
Key Takeaway
Props are how data flows downward in React.
No props β no real app.
Top comments (0)