eslint-plugin-react icon indicating copy to clipboard operation
eslint-plugin-react copied to clipboard

require-default-props: Allow disabling "must have default value" warning but keeping "forbid defaults for required props"

Open ThiefMaster opened this issue 2 years ago • 1 comments

Right now there doesn't seem to be a way to do this.

  • Having to specify a null/undefined default for a prop where you're perfectly fine with it being undefined when not specified feels a bit pointless
  • This is made worse for a prop where you want to allow null, because a required prop will fail runtime proptypes validation when its value is null (even if it's explicitly set to null

So I'd like to just ditch the part of having to specify default for optional props, but still prohibit setting defaults for required ones.

ThiefMaster avatar Dec 01 '23 08:12 ThiefMaster

Some of those cases are why https://npmjs.com/airbnb-prop-types has explicitNull, but an option as you describe seems feasible.

ljharb avatar Dec 01 '23 15:12 ljharb