About Theo's take of not destructuring props
I can't remember in what video exactly, but I heard Theo saying something about using component props without destructuring them. I gave it a go but stumbled on some scenarios where I'm really scratching my head to know how to do properly without destructuring.
Basically it's a matter of default values and prop forwarding
I know only of "defaultProps", but not only it is deprecated, but also adds another layer of indirection by having to read the code below at another place
In the example I gave before, there is a problem: even though I only want to use
Also, the React documentation itself only states destructuring as the way to pass default values to components:
https://react.dev/learn/passing-props-to-a-component#specifying-a-default-value-for-a-prop
Basically it's a matter of default values and prop forwarding
- Default Values
I know only of "defaultProps", but not only it is deprecated, but also adds another layer of indirection by having to read the code below at another place
- Prop Forwarding
In the example I gave before, there is a problem: even though I only want to use
testColor in the p element, when I use ...props in the input element, I'm passing testColor as well, which throws a warning.How it would be with destructured props
Also, the React documentation itself only states destructuring as the way to pass default values to components:
https://react.dev/learn/passing-props-to-a-component#specifying-a-default-value-for-a-prop
