DocumentationRulesno-default-props

no-default-props

Rule category

Restriction.

What it does

Disallows using defaultProps property in favor of ES6 default parameters.

Why is this bad?

The defaultProps will be removed from functional components in React 19 in place of ES6 default parameters. If you’re using defaultProps, it is recommend to migrate to ES6 default parameters.

Examples

Failing

import React from 'react';
 
function ExampleComponent(props) {
  return <div>{props.name}</div>;
}
 
ExampleComponent.defaultProps = {
  name: 'John Doe',
};

Passing

import React from 'react';
 
interface ExampleComponentProps {
  name: string;
}
 
function ExampleComponent({ name = 'John Doe' }: ExampleComponentProps) {
  return <div>{name}</div>;
}