May I ask how to understand this deconstruction assignment in ES6?

const add = (state, { payload }) => {
  return state.concat(payload);
};



Sep.29,2021

If the parameter of the
function is a member of the object, the deconstruction assignment takes precedence.
/ / bad
function getFullName (user) {
const firstName = user.firstName;
const lastName = user.lastName;
}
/ / good
function getFullName (obj) {
const {firstName, lastName} = obj;
}
/ / best
function getFullName ({firstName, lastName}) {
}

getting started with ECMAScript 6


two parameters: one is state, the other is an object taking out the value of the payload field in the object and assigning it to the payload variable. The second is an object deconstructing


// .
add(['a','b'], {payload:['c','d']}) // ['a','b','c','d']
.
Menu