React class components are "old school" now I think, but destructuring is convenient any time you have to work with a complex object in which the properties have to referenced multiple times. That's the use case I'm most familiar with.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Destructuring like so:
const { name: nameNeedsValidation } = req.param
Creates a variable called
nameNeedsValidation
from the propertyreq.param.name
.I find it preferable to destructure in the case of when I'm working on a React class component and the state object is complex (10+ properties).
In the template, instead of having to write:
I can just write:
Note that this would be unconventional:
React class components are "old school" now I think, but destructuring is convenient any time you have to work with a complex object in which the properties have to referenced multiple times. That's the use case I'm most familiar with.