defaultProps stopped working on a function component in React 19
A prop is undefined after upgrading to React 19 although Component.defaultProps sets itShort answer
React 19 removed defaultProps for function components, so the defaults are never applied and props arrive as undefined. Replace them with default values in the parameter destructuring. propTypes checks are also removed and silently ignored. Class components still support defaultProps.
Fix it fast
1Find out which cause you have
List every function component that still sets defaultProps or propTypes. React 18.3 is identical to 18.2 but adds warnings for APIs removed in 19, so run it once to see them all.
grep -rn 'defaultProps\|propTypes' src/2Match what you see, then jump to its fix
What does the error look like?
A prop is undefined after upgrading to React 19 although Component.defaultProps sets itpropTypes warnings no longer appear
Cause 1 of 2
defaultProps on a function component
1Check
Check that the component is a function, not a class. Only function components lost the feature.
grep -rn -B3 'defaultProps' src/ | grep -E 'function|=>|class'2Fix
Move each default into the destructured parameters, and type the prop as optional.
interface Props {
text?: string;
}
function Heading({ text = 'Hello, world!' }: Props) {
return <h1>{text}</h1>;
}3Verify
Render the component without the prop. The default text appears.
npm testConfirmed by react.dev
Cause 2 of 2
propTypes on a function component
1Check
In React 19 the propTypes check is removed from the React package and using it is silently ignored.
grep -rn 'prop-types' package.json src/2Fix
Move to TypeScript or another type checker. The upgrade guide offers a codemod for the conversion.
npx codemod@latest react/prop-types-typescript3Verify
Pass a wrong prop type. The type checker now reports it.
npx tsc --noEmitConfirmed by react.dev
How do I stop it coming back?
- Upgrade to React 18.3 first and clear its warnings before moving to 19.
- Use default parameters for every new component, never defaultProps.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- TaskvareA task and project-management suite: React on the web, Flutter on mobile, TypeScript underneath.
Related fixes
Web apps
TypeScript refuses JSX because the jsx option is not set
TS17004: Cannot use JSX unless the '--jsx' flag is provided.
TypeScript compiles JSX only when you name the file with a .tsx extension and enable the jsx compiler option.
2 causes, each with a fixWeb apps
TypeScript rejects a component that returns an array or other non-Element
Its return type 'Element[]' is not a valid JSX element.
TypeScript before 5.1 required every component to return JSX.Element or null, so arrays, strings and Promises were rejected even though React renders them.
2 causes, each with a fixWeb apps
ESLint says it cannot resolve a path to a module that does exist
Unable to resolve path to module 'react'. import/no-unresolved
import/no-unresolved fails when eslint-plugin-import cannot find the file or package on disk with its resolver.
4 causes, each with a fixWeb apps
ESLint reports no-unused-vars for React components and imports that are used
no-unused-vars reported for a component that is rendered as a JSX tag
ESLint's core no-unused-vars does not see variables used only as JSX tags, so a component imported and rendered as <Hello /> looks unused.
3 causes, each with a fixWeb apps
TypeScript rejects MUI Data Grid columns that set a type
A TypeScript error inside a column's renderCell callback
A columns array declared without a type is inferred with type as a plain string, which the Data Grid's column type union does not accept.
2 causes, each with a fixWeb apps
The renderInput prop stopped working on the MUI X DatePicker
The custom TextField (variant, size, helperText) is ignored
renderInput was removed from the MUI X date pickers in version 6.
3 causes, each with a fix