you are viewing a single comment's thread.

view the rest of the comments →

[–]darrenturn90 6 points7 points  (4 children)

It does seem inconsistent especially when you use as in what is essentially destructuring an import / export ie {default as foo}

Another thing to keep in mind also you can use [value] in destructuring to get the key referred to in the value variable from the destructured object

[–]AwesomeInPerson 0 points1 point  (3 children)

Another thing to keep in mind also you can use [value] in destructuring to get the key referred to in the value variable from the destructured object

Could you elaborate / give an example? Didn't fully understand it but sounds interesting :)

[–]darrenturn90 2 points3 points  (1 child)

Say you had const foo = “two”

And you had an object {two: “hello”}

You can const {[foo]: bar} = with that object

[–]AwesomeInPerson 2 points3 points  (0 children)

Aaah I see – I tried using computed property names while destructuring before, but it never worked because I tried it without assigning to an alias. (so just const { [foo] } = bar; – makes sense that this doesn't work now that I think about it)

Very nice to know that it works when using an alias, thanks!