The destructuring argument is unconvincing: the "old fashioned" code is extremely clear, easier to update if the structure of the object changes, and allows one to change the variable name, if needed, for even more clarity, e.g.
const nameNeedsValidation = req.param.name.
As others have noted, the Object Spread comment about needing looping is wrong: Object.assign() does the job nicely. IMO, it is also clearer than using spread, but I admit that's just my opinion.
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.
The destructuring argument is unconvincing: the "old fashioned" code is extremely clear, easier to update if the structure of the object changes, and allows one to change the variable name, if needed, for even more clarity, e.g.
const nameNeedsValidation = req.param.name
.As others have noted, the Object Spread comment about needing looping is wrong:
Object.assign()
does the job nicely. IMO, it is also clearer than using spread, but I admit that's just my opinion.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.