What do the braces mean in the following function definition?
(state, { copy }) => state.push(createItem(copy));
What do the braces mean in the following function definition?
(state, { copy }) => state.push(createItem(copy));
In ES6, this is known as Object Destructuring.
In that particular aspect, it means I can pass an object in as a parameter of a function and it gets transformed into variables that I can access within that function, for example:
function f(param1, { param2, param3 }) {
console.log(param2, param3)
}
f("one", {
param2: "A",
param3: "B"
});
The advantage being that instead of calling:
f("one", myObject.one, myObject.two);
I can simply call:
f("one", myObject);
And the one
, two
parameters will be mapped for me accordingly.