3 ms·
I would argue that object unpacking is superior unless you have something similar to useState, where you only return two variables, and you know you'll never ne
by depressedpanda 5y ago
I would argue that object unpacking is superior unless you have something similar to useState, where you only return two variables, and you know you'll never need the second variable without the first (which in practice may be very difficult to know beforehand, as requirements change).
Object unpacking also allows you to alias the variable names, though it's slightly more verbose: `const { foo: newName } = someThing()`.
You can also choose to forgo unpacking entirely and just use the natural namespacing returning an object would provide:
const thing = someThing()
thing.foo()
thing.bar()