bradxr
8/4/2018 - 12:39 PM

Use Destructuring Assignment to Pass an Object as a Function's Parameters

Destructure an object in a function argument

// destructure the profileData object sent into function as a parameter
const profileUpdate = ( profileData ) => {
  const { name, age, nationality, location } = profileData;
  // do something with these variables
}

// the above can also be done in-place
const profileUpdate = ( { name, age, nationality, location } ) => {
  // do something with these variables
}