Posts by eivindml

All posts

Don't Destructure Your Props!

I came across this example on Reddit.

Massive prop desutrcturing

It seems to be very common to destructure props in React. I don't know why people are doing it, but please stop doing that! Referring to variables as props.title, for example, is a feature not a bug. It makes it immediately clear that the data comes from the component's props and not from somewhere else. Additionally, we can quickly see all available properties in the props object through autocomplete.

It's possible to add an ESLint rule to trigger an error (or just a warning) if someone tries to destructure the props.

"react/destructuring-assignment": ['error', 'never']