【发布时间】:2020-04-13 21:11:09
【问题描述】:
我有来自 youtube 教程的代码,我不知道为什么我们需要括号(注释行),如果有人可以简单地解释这段代码...谢谢
const [{count, count2}, setCount] = useState({count: 10, count2: 20})
return (
<div className="App">
<button onClick={ () =>
setCount(
currentState => (//can not understand
{...currentState, count: currentState.count+1}
)
)}>+</button>
<h5>Count 1: {count}</h5>
<h5>Count2: {count2}</h5>
</div>
)
【问题讨论】:
标签: javascript reactjs jsx