Concept Flow - Default props
Component Called
Check Props Passed?
Yes No
Use Passed Props
Render Component
When a React component is called, it checks if props are passed. If not, it uses default props before rendering.
function Greeting({ name = "Guest" }) { return <h1>Hello, {name}!</h1>; } <Greeting /> <Greeting name="Alice" />
| Step | Component Call | Props Passed | Name Value Used | Rendered Output |
|---|---|---|---|---|
| 1 | <Greeting /> | No | "Guest" | <h1>Hello, Guest!</h1> |
| 2 | <Greeting name="Alice" /> | Yes (name="Alice") | "Alice" | <h1>Hello, Alice!</h1> |
| Variable | Start | After Call 1 | After Call 2 | Final |
|---|---|---|---|---|
| name | undefined | "Guest" | "Alice" | "Alice" |
Default props in React let components use fallback values when no props are passed.
Use function parameter defaults like ({ name = "Guest" }) to set them.
If a prop is passed, it overrides the default.
This ensures components always have values to render.
No need for separate defaultProps with modern React.