We just made this code based on a hunch, and it worked. I'm pretty sure it's acceptable. I just want to make sure:
const state = { inProgress: true }
const actions = 'COMPLETE_RICE'
const change = { inProgress: false, rice: 'cooked' }
// Is this destructuring OK?
const {
0: newState,
1: newActions,
2: newChange,
} = [state, actions, change]
console.log('New State:', newState)
console.log('New Actions:', newActions)
console.log('New Change:', newChange)
Is there a better way to do this?
Any concerns or violations?
I can't find any examples of this and only tried it because I recalled that:
['one', 'two', 'three'] can be expressed as an object:
{
0: 'one',
1: 'two',
2: 'three'
}
It's not exactly listed here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment
But, it works.
const [newState, newActions, newChange] = [state, actions, change]const [newState, newActions, newChange] = [state, actions, change]but using object like you are doing is just not too nice. It will work but why doing it weird way :)