Pages

Topics

Tools

↑↓navigate↵openescclose
All guides

React 19: Support for defaultProps will be removed

React 19 ignores defaultProps on function components, so a default becomes undefined. Move defaults into the parameter list and handle null honestly.

~5 min readReact
#react#react-19#defaultprops#migration
Bold white headline reading NO DEFAULTPROPS with a React component crate holding an amber empty props plate beside a cyan default parameter slot.

Introduction & Quick Summary

A component library upgraded to React 19 renders with empty buttons, and the console shows:

code
Warning: Support for defaultProps will be removed from function components in a future major release. Use JavaScript default parameters instead.

Quick answer: React 19 stopped reading defaultProps on function components. Move each default into the parameter list, where it also survives destructuring and TypeScript.

jsx
// before: ignored in React 19 function Button({ variant, size }) { return <button className={`${variant} ${size}`} />; } Button.defaultProps = { variant: "primary", size: "md" }; // after: applied at call time function Button({ variant = "primary", size = "md" }) { return <button className={`${variant} ${size}`} />; }

The warning appears in React 18.3, which added it as a migration aid, and React 19 drops the behaviour entirely. That means a component whose defaults lived in defaultProps does not crash; it renders with undefined where a value used to be. Empty class names, missing placeholders and NaN in calculations follow, often far from the component itself.

Classes are unaffected: static defaultProps on a class component still works in React 19. So do object defaults you write inside the component body. The removal targets one specific pattern, and knowing exactly which one keeps the migration small.

Core Mechanics, Signatures & Reproducible Setup

Reproduce with a component that relies on the old pattern:

bash
npm create vite@latest dp-demo -- --template react-ts cd dp-demo && npm i && npm i react@19 react-dom@19
jsx
function Badge({ tone, label }) { return <span data-tone={tone}>{label}</span>; } Badge.defaultProps = { tone: "neutral" }; export default function App() { return <Badge label="new" />; // data-tone is undefined in React 19 }

defaultProps was resolved by createElement, which merged the component's defaultProps into the props object before the component ran. In React 19, createElement no longer looks at defaultProps for function components, so the props object arrives exactly as written at the call site. A default parameter, by contrast, is applied by the JavaScript engine when the destructured property is undefined.

Component formdefaultProps in React 18defaultProps in React 19Recommended replacement
Function componentappliedignoreddefault parameters
Class componentappliedstill appliedstatic defaultProps is fine
memo(Component)applied to the inner componentignoreddefaults inside the component
forwardRef(render)never appliednever applieddefaults in the render parameters
lazy(() => import(...))applied to the resolved componentignoreddefaults inside the component

Key Comparison Table

ApproachSyntaxDefault when prop is nullRe-created each render
Default parameter({ size = "md" })no, null stays nullno
Nullish coalescingconst s = size ?? "md"yesno
Component body ifif (!size) size = "md"yes, also for "" and 0no
defaultPropsC.defaultProps = {...}not in React 19no
Default object({ items = [] })noyes, a new array per render

What each component type does with defaults:

SituationReact 18.3React 19Action
Function component with defaultPropswarnsignoresmigrate to parameters
Class component with defaultPropsworksworksleave it
memo wrapper with defaultPropsworks, warnsignoresmove defaults inward
forwardRef with defaultPropsignores, no warningignoresset defaults in the render function
Library shipping defaultPropswarns in your consolesilently ignoresupgrade the library

Practical Edge Cases, Error Fixes & Deep Dive Code Examples

1. Defaults that depend on other props

A default parameter cannot see the rest of the props object, so dependent defaults move into the body:

jsx
function Card({ size = "md", padding = size === "sm" ? 8 : 16, children }) { return <section style={{ padding }}>{children}</section>; }

This works because destructuring binds left to right, and a later default can reference an earlier binding. When the dependency runs the other way, compute it explicitly:

jsx
function Card({ size, padding, children }) { const resolvedSize = size ?? "md"; const resolvedPadding = padding ?? (resolvedSize === "sm" ? 8 : 16); return <section style={{ padding: resolvedPadding }}>{children}</section>; }

Reading a prop twice is fine; the failure mode to avoid is a default that silently disagrees with another prop's default.

2. null versus undefined

Default parameters apply only when the argument is undefined. <Input value={null} /> keeps null and skips the default, which matters for controlled inputs:

jsx
function Input({ value = "", onChange }) { return <input value={value} onChange={onChange} />; } <Input value={null} /> // React warns about value going null to a string <Input value={undefined} /> // default applies, value is ""

When null must also fall back, use ?? inside the component. || is the wrong operator for numeric or boolean defaults because it replaces 0 and false.

3. memo, forwardRef and lazy

jsx
const Row = memo(function Row({ selected = false, children }) { return <li aria-selected={selected}>{children}</li>; }); const FancyInput = forwardRef(function FancyInput( { placeholder = "Type here", ...rest }, ref, ) { return <input ref={ref} placeholder={placeholder} {...rest} />; });

memo returns a wrapper object, and React 19 does not forward defaultProps from that wrapper to the inner function. Writing defaults inside the wrapped function covers every wrapper in one move. forwardRef never applied defaultProps in any version, which is why some components have looked broken for years without a warning. Spread props after defaults in JSX so a caller's placeholder still wins.

4. Libraries and design systems

A dependency that still ships defaultProps produces the warning from inside node_modules, and the fix belongs to that package, not your app:

bash
npm ls react npm outdated

Upgrade the library if a release note mentions React 19 support. When the package is unmaintained, wrap it once instead of patching node_modules:

jsx
function LegacyCard(props) { return <Card {...{ variant: "outlined", ...props }} />; }

The spread order gives the default first and the caller's value second, which reproduces the old behaviour exactly. This wrapper also isolates the workaround so it can be deleted when the package catches up.

5. Class components, PropTypes and typing

static defaultProps on a class keeps working, so a mixed codebase needs no change there:

jsx
class Panel extends React.Component { static defaultProps = { open: false }; render() { return <div hidden={!this.props.open} />; } }

React 19 removed propTypes checking entirely, so a component that relied on PropTypes for defaults never had them: PropTypes only validated. For TypeScript, mark the props optional and let the parameter default narrow the type:

tsx
type ButtonProps = { variant?: "primary" | "ghost"; size?: number }; function Button({ variant = "primary", size = 12 }: ButtonProps) { const v: "primary" | "ghost" = variant; // already narrowed return <button data-v={v} style={{ fontSize: size }} />; }

TypeScript 5.1 and later infer the default's type into the destructured binding, so an explicit annotation is rarely needed. A package.json diff between the old and new version of a library is often enough to spot the peer range that changed; the JSON formatter makes that comparison readable.

6. Tests, Storybook and server rendering

A test that renders a component with no props exercises the defaults, which is exactly where a React 19 upgrade breaks silently:

jsx
import { render, screen } from "@testing-library/react"; test("badge falls back to the neutral tone", () => { render(<Badge label="new" />); expect(screen.getByText("new")).toHaveAttribute("data-tone", "neutral"); });

Storybook stories that rely on implicit defaults show undefined after the upgrade for the same reason, and server-rendered markup differs from the previous release, so snapshot tests need regenerating once. Treat any snapshot diff that only adds or removes default attribute values as a signal, not noise. Searching a codebase for the pattern is quick with the regex tester: \.defaultProps\s*=.

Common Compilation/Runtime Mistakes & Version Gotchas

Deleting defaultProps without adding defaults. The code compiles and renders undefined; TypeScript only complains if the prop is required. Add the parameter default in the same commit.

Assuming the warning is cosmetic. In React 18.3 it is; in React 19 the values are gone. Upgrade order matters: fix the defaults before moving to 19.

Using || as a replacement. size || "md" turns 0 into "md" and false into the default. Use ?? or a parameter default.

Setting defaults on the exported wrapper. export default memo(Button) then Button.defaultProps sets a property on the memo object, which React never reads. Put defaults inside the function.

Relying on propTypes for defaults. PropTypes.string.isRequired with defaultProps was a common pair; React 19 removes the validation layer, so only the explicit default remains.

Version notes. React 18.3 is the only 18.x release that warns; 18.2 and earlier are silent, which is why a codebase can upgrade to 19 and notice nothing until a screenshot review. React 19 also removed propTypes, string refs, ReactDOM.render and ReactDOM.findDOMNode, so a defaultProps migration usually lands beside those changes. React Native follows the same rule for function components from 0.76 onward.

Reference material: React 19 release notes and Component.

Official references

primary documentation

The React documentation that defines the behaviour this guide explains.

Try matching browser tools

All tools

Small utilities that fit React work — they run entirely in this browser tab, so nothing you paste leaves your device.

All React guides

More in React

All React guides

The guides filed next to this one in React, in library order.