# 关于 React hooks 的 caputre value,以下输出多少
更多描述
function App() {
const [count, setCount] = useState(0);
const incr = () => {
setTimeout(() => {
setCount(count + 1);
}, 3000);
};
return <h1 onClick={incr}>{count}</h1>;
}
当连续点击 10 次时,会输出多少
Issue
欢迎在 Gtihub Issue 中回答此问题: Issue 373 (opens new window)
Author
应该是 1 吧,在 state 被 update 之前 count 一直还是 0
Author
连续点击 10 次是在 3s 内完成,那传给 setTimeout 的 count 都为 0,输出应该都是 1
Author
验证一下 https://codesandbox.io/s/sharp-dawn-5e5hp?file=/src/capture.js