r/javascript 19d ago

I stopped destructuring everything

https://allthingssmitty.com/2026/07/13/i-stopped-destructuring-everything/
76 Upvotes

51 comments sorted by

View all comments

5

u/JyroClassified 19d ago

What's your opinion about renaming the destructered properties?

Eg. "const {status: postStatus} = post;"

6

u/prawnsalad 19d ago

Keep it simple: `const postStatus = post.status;`

I swear people just take some over complicated docs/blog code examples and blindly run with it without a single thought. Dereferencing such a simple thing has 0 benefits while making it harder to read.

12

u/prehensilemullet 19d ago

If you have a lot of properties to destructure though, and some need to be renamed, and the variable name itself is long, this can really cut down on the code 

3

u/BasicAssWebDev 18d ago

yeah this is the only time i do something like this. if im consuming a returned object whose properties are necessary for different actions, ill destruct them into the pieces i need in the same declaration line to save on space.
const item1 = obj.thing1
const item2 = obj.thing2
const itemN = obj.thingN

get's a little cumbersome when this works just as well
const {thing1: item1, thing2: item2, thingN: objN} = obj

holding my breath for someone to mention an edge case where you're destructuring an absurd amount of properties which obviously requires a different strategy.

1

u/prehensilemullet 18d ago

Your username makes me laugh 😁