Props (short for properties) are how parent components pass data and callbacks to children. They are read-only and flow one way down the tree. This lesson covers prop syntax, defaults, validation, and common patterns.
Props as Component Inputs
When you render <Avatar name="Ada" size={48} />, React passes an object { name: 'Ada', size: 48 } as the first argument to Avatar. The child uses those values to decide what to render.
Props must never be mutated inside the child. If a child needs to change data, it calls a callback prop provided by the parent, which updates state upstream and flows new props down.
Functions can be props too — onEdit lets the child notify the parent without owning modal state.
Prop Patterns
// Destructuring with defaults
function Badge({ label = 'New', color = 'blue' }) { ... }
// Rest props (forward to DOM)
function Input({ label, ...inputProps }) {
return <label>{label}<input {...inputProps} /></label>;
}
// Boolean shorthand
<Button disabled /> // same as disabled={true}
Destructure props in the function signature for readability.
Provide default values for optional props.
Use {...rest} to forward unknown props to native elements.
Boolean props can omit ={true} for brevity.
Props Cheat Sheet
Essential prop patterns in React.
Pattern
Example
String prop
<Title text="Hello" />
Expression prop
<Counter initial={count} />
Function prop
<List onSelect={handleSelect} />
Children prop
<Card>content</Card>
Spread props
<Input {...register('email')} />
Default value
function X({ n = 0 })
Renamed prop
function X({ className: cn })
Prop Drilling and When It Hurts
Prop drilling means passing props through many intermediate components that do not use them, only forwarding down. It is fine for shallow trees; for deep sharing, consider composition, context, or a state library.
Composition: pass JSX as children instead of props through layers.
Context: share theme, auth, or locale without drilling.
State libraries: Redux/Zustand for complex global client state.
Colocate state closer to where it is used when possible.
Validating Props
In JavaScript projects, PropTypes (prop-types package) offer runtime checks in development. In TypeScript projects, interfaces and types catch prop errors at compile time — the preferred approach for new apps.