我现在正在学习反应。我知道如果我在这里添加大括号,我可以在这里添加多个语句,但我不明白为什么我需要括号。
class Component extends React.Component {
state = {
count: 0,
};
render() {
return (
<div>
<p>{this.state.count}</p>
<button
onClick={() => {
console.log("clicked");
this.setState((state) => ({
...state,
count: state.count + 1,
}));
}}
> Click
</button>
</div>
不过我用this.setState的时候,我觉得这个应该是对的
this.setState((state) => {
...state,
count: state.count + 1,
});
}}
我知道我认为正确的实际上是错误的但无法理解添加括号 有人能帮我解决这个问题吗?