require-default-props
UnreleasedConfiguration
Rule Details
Require a default value for every optional component prop. The rule checks runtime
propTypes declarations and locally declared TypeScript prop types.
Examples of incorrect code:
Examples of correct code:
Required props do not need defaults. An external defaultProps assignment that
cannot be resolved, or a spread in the defaults object, skips the component to
avoid reporting defaults supplied elsewhere.
Options
Default arguments
For function components using default parameters, configure:
Examples of incorrect code with this option:
Examples of correct code with this option:
This mode reports defaultProps on function components and requires optional
props to have defaults in the destructured parameter. It also reports defaults
for required destructured props, independently of forbidDefaultForRequired.
Required props
With this option, a prop declared as PropTypes.string.isRequired must not also
appear in defaultProps.
When Not To Use It
Disable this rule when optional props may intentionally remain undefined.
Differences from ESLint
React.memoandReact.forwardRefcomponents honorfunctions: "ignore"and"defaultArguments"; eslint-plugin-react v7.37.5 treats their wrappers separately.- Optional props named
toString,constructor, or other inherited object names need explicit defaults. Upstream can mistake inherited properties for defaults. - Inline class props types and props types declared inside functions are checked; upstream can skip these optional props.
- Reading
Component.defaultPropsdoes not suppress missing-default diagnostics; upstream can treat that read as an unresolved default declaration. - Multiple component values assigned to the same binding produce one diagnostic per prop contract. A later component is still checked after a non-component value.
- Components nested in an object assigned to a member retain their complete
external path; upstream can miss declarations such as
ns.registry.C.propTypes.