In React, props (short for properties) are used to pass data from one component to another, primarily from parent to child components.
function Welcome(props) {
return <h1>Hello, {props.name}!</h1>;
}
// Usage
<Welcome name="Rohan" />
function Welcome({ name }) {
return <h1>Hello, {name}!</h1>;
}
<Welcome name="Anjali" />
props.
function Welcome({ name = "Guest" }) {
return <h1>Hello, {name}!</h1>;
}
Props are immutable (cannot be changed by the child). If changes are needed, the parent must pass new props.
useState.Props make React components dynamic, reusable, and more adaptable to various data inputs without changing their structure.