DEV Community

Discussion on: Do Whatever You Want, So Will I

Collapse
 
reergymerej profile image
ᴙɘɘᴙgYmɘᴙɘj

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