Comments (6)
Yes, with the react team’s very unwise and unfortunate decision in 18.3/19, we might as well add both things.
from eslint-plugin-react.
The rule forbids default props, not default function parameters. In other words, the .defaultProps
object attached to the component.
from eslint-plugin-react.
@ljharb I understand that the current focus is solely on .defaultProps
. However, is there any current or future support for performing a different type of validation?
The proposed validation would cover two aspects:
- If there are required props, ensure they do not have a default value.
- For non-required props, ensure they have a default value.
All of the above should always be validated with the function parameters.
from eslint-plugin-react.
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).
from eslint-plugin-react.
@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?
from eslint-plugin-react.
@ljharb Regarding point 1, could we re-evaluate it? Facebook already made changes in React Dom (v18.3.0) to start throwing warnings when .defaultProps
is used in functional components, but not for class ones.
See more: facebook/react@5894232
from eslint-plugin-react.
Related Issues (20)
- Proposal for Stringent Type Checking HOT 3
- [Bug]: Support for Eslint 9.0.0? HOT 1
- [Bug]: react/boolean-prop-naming - Cannot read properties of undefined (reading 'properties') HOT 1
- [Bug]: peer dependency error with eslint@9 HOT 1
- [Bug]: An incomprehensible mistake HOT 3
- [help wanted] The functions option (defaultArguments) in the react/require-default-props rule does not work as expected. HOT 1
- [Bug]: HOT 3
- Add "line-aligned" to react/jsx-closing-tag-location HOT 7
- [Bug]: Properties faulty identified as not declared for types in react-hook-form HOT 1
- [Bug]: checkKeyMustBeforeSpread of react/jsx-key doesn't work when generating array dynamically
- [Bug]: Endless listing cycle HOT 4
- [Bug]: The endless linting cycle HOT 1
- [Bug]: Rule "react/no-direct-mutation-state" failing in a stateless component HOT 1
- Remove `react/prop-types` from the recommended config HOT 1
- `jsx-no-leaked-render` should only complain if there is a certian leaked render HOT 5
- Quick question: does `settings.version` default to "detect" yet? HOT 3
- [Bug]: Unable to use with eslint 9.x HOT 1
- `jsx-no-leaked-render` can work better if it checks the TS type of the left-side value HOT 1
- [Bug]: react/boolean-prop-naming not working with TS & declaration HOT 1
- with redux there is not necessary error
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from eslint-plugin-react.