vasanthk / react-bits

✨ React patterns, techniques, tips and tricks ✨
https://vasanthk.gitbooks.io/react-bits
Creative Commons Attribution 4.0 International
16.97k stars 1.1k forks source link

Add `...rest` solution to spreading-props-dom anti-pattern #78

Closed camjackson closed 7 years ago

camjackson commented 7 years ago

This is the approach mentioned in the official docs here: https://reactjs.org/warnings/unknown-prop.html. Which is not to say that it's better than what's currently in this repo, but it can't help to list a couple of ways to solve the problem :)

FezVrasta commented 7 years ago

Actually the whole page is kinda opinable... People shouldn't pass "random" props to the child components and hope that the child component doesn't apply them to the underlying HTML tags.

The right approach is to make all the properties get redirected/applied to the underlying HTML tags and apply to the component only the properties that are supposed to be there.

Just my 2 cents obviously

vasanthk commented 7 years ago

I agree with @FezVrasta that passing random props using spread operator might not be the cleanest way to handle them (especially when it is applied to DOM elements). However, it helps at times when applying to Components and might give an idea for users on its usage. Thanks :)

FezVrasta commented 7 years ago

@vasanthk I was speaking in favor of this PR and against the rest of the existing page 🙃