To set default prop values in React, give the prop a default in the destructured parameter list of your function component, for example function Button({ size = "md" }). React uses the default only when the prop is missing or undefined. This replaces the old Component.defaultProps pattern, which React 19 no longer supports on function components.
React default props make a component easier to use because callers only pass what they want to change.
The standard way is a JavaScript default in the parameter destructuring.
The first button gets size="md" and variant="primary". The second overrides only variant. This is plain JavaScript, so it works the same way anywhere you destructure.
A default applies only when the value is undefined. That includes a prop that was not passed and one passed explicitly as undefined.
| Prop passed | Value inside the component |
|---|---|
| Not passed | The default |
size={undefined} | The default |
size={null} | null, no default |
size="" | An empty string, no default |
size={0} | 0, no default |
The null case surprises many people. If a parent may pass null and you want a fallback, handle it explicitly:
The ?? operator falls back for both null and undefined.
A default can be any expression. Be careful with objects and arrays, because a new one is created on every render.
This is fine for simple rendering. The new empty array on each render only matters if you pass it to a memoised child or put it in a useEffect dependency list. In that case define the default outside the component:
Older code sets defaults as a static property:
React 18 logged a warning for this on function components, and React 19 ignores defaultProps on them entirely, so the default silently stops working after an upgrade. Class components still support static defaultProps. Moving to parameter defaults also keeps the default next to the code that uses it.
The same applies to propTypes, which React 19 no longer checks.
With TypeScript, mark the prop optional and give the default in the parameter list. Inside the function, the type is narrowed because the default fills the gap.
Callers can omit size, and size inside Button is typed as one of the three literals, never undefined.
A default fits props that have a sensible fallback, such as size, variant or an empty list. For data a component cannot work without, such as a user ID, do not invent a default. Make it required in the type so that forgetting it is a compile error rather than a quiet wrong render.
Not on function components. React 19 ignores it, so use default parameter values. It remains supported on class components.
Defaults apply to undefined only. Use the ?? operator or check for null yourself.
Yes. Parameter defaults can reference earlier parameters, but with destructured props it is clearer to compute the value in the body, for example const id = props.id ?? props.name.
No. Only give defaults to optional props that have an obvious fallback.
Set default prop values in React with default parameters in the destructured props, such as { size = "md" }. The default applies when the prop is missing or undefined, not for null. Replace defaultProps and propTypes in function components before upgrading to React 19, and define shared object or array defaults outside the component to keep their identity stable.