const someFunction = ({ a }) => {
const { b } = a;
return <div>{b}</div>
}
const obj = { a: { b: 1 } }
someFunction(obj)
Is there a way to chain object destructuring so that in someFunction, we can destructure obj to get b within the parameter instead of having to do a separate const { b } = a in the function body?
You can do it like so:
const someFunction = ({ a: { b } }) => {
return b;
}
const obj = { a: { b: 1 } };
console.log(someFunction(obj));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With