react setstate add to object code example
Example 1: Updating an object with setState in React
this.setState(prevState => {
let jasper = Object.assign({}, prevState.jasper);
jasper.name = 'someothername';
return { jasper };
})
this.setState(prevState => ({
jasper: {
...prevState.jasper,
name: 'something'
}
}))
Example 2: setstate find opject in state and update
this.setState(prevState => ({
food: {
...prevState.food,
pizza: {
...prevState.food.pizza,
extraCheese: true
}
}
}))
Example 3: can we add new state property using setstate in react
How to become a pro with React setState() in 10 minuteswww.freecodecamp.org › news › get-pro-with-react-set...