Warning: Support for defaultProps will be removed from function components
Error message
Support for defaultProps will be removed from function components in a future major release.
Quick summary
You set `Component.defaultProps` on a function component, which is deprecated. Use JavaScript default parameters instead.
Why this happens
Used
MyComponent.defaultProps = { ... }on a function componentCopied a pattern from class components to function components
Minimal example
✗ Broken code
function Button({ label }) {
return <button>{label}</button>;
}
Button.defaultProps = { label: "Click" }; // Deprecated!✓ Fixed code
function Button({ label = "Click" }) {
return <button>{label}</button>;
}Default parameters in the function signature are the modern way to set default prop values for function components.
How to diagnose
Search for
.defaultPropsin the codebaseCheck if it's applied to a function component
How to fix
Use default parameters:
function MyComponent({ prop = defaultValue })Destructure with defaults:
function MyComponent({ prop = 'default' })
How to prevent
Always use default parameters for function component defaults
Only use defaultProps for class components (also deprecated)