DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 963,274 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in

Discussion on: Do Whatever You Want, So Will I

Collapse
 
reergymerej profile image
α΄™Ι˜Ι˜α΄™gYmΙ˜α΄™Ι˜j Author

That's a good article and I agree with a lot of it. In general, the problem with spreading props is obscurity and messiness. Child components end up accumulating a lot of stuff that is not meant for them and the origin can become obscured.

Even the React docs state...

Spread attributes can be useful but they also make it easy to pass unnecessary props to components that don’t care about them or to pass invalid HTML attributes to the DOM. We recommend using this syntax sparingly.

Collapse
 
maybebored profile image
Mayuran

Agreed. It would be more precise to say passing unnecessary props to a component is a bad practice. Spreading props is merely a technique allowed by JS. This got me thinking, does React warn when a component receives an unexpected prop, and turns out there is a pluggable solution - github.com/airbnb/prop-types-exact