我想在以下问题中扩展状态更新
React Hooks, rerender & keeping same state - how it works underhood?
更新 {count} 的两种方式有区别吗?
它们是严格等价的吗?
<button onClick={()=>setCount**(count+1)**} >{count}</button>
<button onClick={()=>setCount(**savedCount => savedCount+1)**}{count}</button>
提前致谢
最佳答案
不,他们不是。您应该更喜欢最新的,因为它保证 count
您正在使用的是最新版本。直接与 count
合作时而不是 savedCount
,它可能有一些更新仍未应用。
关于reactjs - react 钩子(Hook) : difference between setting the state with an argument or an arrow function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60710256/