0

Is there a nicer way to do this?:

const {
  valueA,
  valueB,
  valueC,
  valueD,
  valueE,
  valueF
} = this.state;

const newObjectWrapper = {
  valueA,
  valueB,
  valueC,
  valueD,
  valueE,
  valueF
};

dispatch(setNewValues(newObjectWrapper));

I'm trying to de-structure some of the items in state(not all of them, which is annoying otherwise I could just pass state) and then place them inside a new object so I can group them up before adding them to a store. Is there a nice shorter way to do this?

spengos
  • 123
  • 9

1 Answers1

0

Source

function whois({ displayName, fullName: {firstName: name} }) {
  console.log(displayName + ' is ' + name);
}

var user = { 
  id: 42, 
  displayName: 'jdoe',
  fullName: { 
      firstName: 'John',
      lastName: 'Doe'
  }
};

whois(user); // "jdoe is John"
codejockie
  • 5,692
  • 3
  • 29
  • 36