-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[Bug]: The forbidDefaultForRequired
option in the react/require-default-props
rule does not work as expected
#3720
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The rule forbids default props, not default function parameters. In other words, the |
@ljharb I understand that the current focus is solely on The proposed validation would cover two aspects:
All of the above should always be validated with the function parameters. |
The first one seems like a great enhancement. The second one, however, i don’t agree with and wouldn’t want to encourage people to do. Despite the react team’s position, defaultProps are much better than default arguments, because they’re introspectable from the outside (and they work on class components). |
@ljharb I understand your position regarding point 2, can we revisit it in the future for more feedback on this? I still think it would be nice to provide some support for this, maybe not encourage its use, but have it available as a utility. Regarding point 1, I think it's great that it can be taken. Would this be validated on default arguments? |
@ljharb Regarding point 1, could we re-evaluate it? Facebook already made changes in React Dom (v18.3.0) to start throwing warnings when See more: facebook/react@5894232 |
Yes, with the react team’s very unwise and unfortunate decision in 18.3/19, we might as well add both things. |
Is there an existing issue for this?
Description Overview
The
forbidDefaultForRequired
option in thereact/require-default-props
rule does not work as expectedUsing the
react/require-default-props
rule together with theforbidDefaultForRequired
option set totrue
does not throw an error or warning when a prop that is required is assigned a default value.Eslint rule
Example code:
In the previous examples the
foo
prop is required, but it is being assigned a default value, with theforbidDefaultForRequired
option set totrue
, without throwing errors or warnings.Expected Behavior
The expected behavior is that if a prop is mandatory and a default value is assigned, it should throw an error or warning depending on the rule configuration.
eslint-plugin-react version
7.32.2
eslint version
8
node version
18
The text was updated successfully, but these errors were encountered: