Quick question about destructuring in React
state = {
cat: 'meow',
dog: 'bark',
fish: 'what sound do i make?',
snake: 'im not wanted for this experiment',
turtle: 'im also not wanted for this experiment'
}
const {cat, dog, fish } = this.state;
const animals = { cat, dog, fish };
this.pets(animals)
This is obviously just an example but I find myself in similar situations when I'm destructuring by retyping the same variables. I'm hoping there was easier way of doing this? Something like this:
const animals = {cat, dog, fish} = this.state
Or Is it a bad practice to pass the variables directly into the function? (it could end up being a long list of variables)
const {cat, dog, fish} = this.state
this.pets(cat, dog, fish}