In this lesson on state hooks, we have this code:
handleChange({ target }){
const { name, value } = target;
this.setState((prevState) => ({
...prevState,
newTask: {
...prevState.newTask,
[name]: value,
id: Date.now()
}
}));
}
I’m a little confused. What does ...prevState
do, and what does putting an anonymous function in this.setState()
do? I didn’t know we could do that, and I don’t understand why they’re doing it.
This is from the AppClass.js
class component version, not the function component version.