I'm new to React, just have a question on setState method. Let's say we have a component:
class MyApp extends React.Component {
state = {
count: 3
};
Increment = () => {
this.setState((prevState) => ({
options: prevState.count + 1)
}));
}
}
so why we have to use prevState in the setState method? why can't we just do:
this.setState(() => ({
options: this.state.count + 1)
}));
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…