Comments (2)
I think you're getting confused as the examples on the JSX Spread page contradict the anti-pattern. Spreading to HTML elements is actually a very handy feature for being able to pass through props as HTML attributes which, from my point of view, you don't wan't to add to your component properties. A good example is a TextField component: you want it to have a specific set of component defined attributes (type="text" autocomplete="off" ...), but also support all other HTML attributes. For this to work, spread first in the HTML element, then add yours to the right, which will override props before.
The actual anti-pattern is to not spread props passed into a component which don't belong to HTML. To handle such cases, I usually use a function "omitOwnProps(this)" and spread the return value. The function reads the static defaultProps and creates an object that takes the supplied props and omits all properties from defaultProps (needs a different form for stateless components).
from react-bits.
Thanks for the explanation. I was surely confused because spread props on components is the heart of react. Second scenario, spread props on HTML can be handy but it is up to us to ensure properties are valid.
from react-bits.
Related Issues (20)
- DI in React link Page not found HOT 1
- gitbook link gives 401 unauthorized error HOT 3
- ReadMe Redirection Links not working HOT 3
- `domProps` props on DOM elements HOT 1
- “Conventions” reflect neither community conventions nor React team recommendations HOT 2
- React Loadable HOT 2
- [REQUEST] This is very useful - May I add this link in awesome react? HOT 2
- Misleading Anti-Patterns HOT 2
- Extend event handlers with an example of arrow function in class property HOT 1
- Best practices for role-based UI HOT 3
- Name for props of component prop use?
- Remove plagiarized content HOT 1
- [Using Indexes as Key] Misleading information HOT 1
- Is there any solution or practice for 2127 issue?
- Linter HOT 1
- Typescript branch
- What about using an object? HOT 2
- Is it OK to fork it and translate into other language by myself? HOT 4
- List components
- Possible typo in 18.conditionals-in-jsx.md under "do expression" section HOT 2
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 react-bits.