In React, props (short for properties) are read-only inputs that are passed from a parent component to a child component. They allow components to be reusable and dynamic by enabling data and configurations to flow down the component tree.
Think of props like function parameters:
- A component is like a function.
- Props are the arguments you pass into it.
🔹 Key Points about Props:
- Immutable (Read-only) – A child component cannot change its props; they are controlled by the parent.
- Passed down from parent to child – Data always flows top → down (unidirectional data flow).
- Allow reusability – You can pass different values into the same component to render dynamic content.
- Any type of data – Props can be strings, numbers, arrays, objects, or even functions.
🔹 Example: Using Props
// Child Component
function Greeting(props) {
return <h1>Hello, {props.name}!</h1>;
}
// Parent Component
function App() {
return (
<div>
<Greeting name="Himanshu" />
<Greeting name="Anita" />
<Greeting name="John" />
</div>
);
}
✅ Output:
Hello, Himanshu!
Hello, Anita!
Hello, John!
Here:
- The App component passes
nameas a prop to Greeting. - Greeting uses
{props.name}to display different names.
👉 In short: Props are the way components communicate with each other in React, by passing data from parent to child.
