Reputation: 2636
I'm trying to create an object from destructing parameters of my function
const myFunc = ({foo,bar,baz},something,{x,y,z}) =>{
console.log(someObjectThatContainsFooBarBaz); // {foor,bar,baz}
console.log(someObjectThatContainsXYZ); // {x,y,z}
}
I've tried ({foo,bar,baz}=props)=>...
and ({foo,bar,baz}:props)=>...
already, but none of these works.
Can someone tell me what should I do about this?
Upvotes: 0
Views: 49
Reputation: 386550
You need another step for creating a new object.
This is not possible to destructure an object and at the same time create a new one with the destructured variables.
const myFunc = ({ foo, bar, baz }, something, { x, y, z }) => {
console.log({ foo, bar, baz }); // new object
console.log({ x, y, z }); // new object
}
Upvotes: 3