[英]How to get updated useState() value inside timeout function?
I'm currently trying to get the latest updates into a timeout function.我目前正在尝试将最新更新放入超时 function。 This means I want to have
c
updated to 1
without having to use something like the useRef
hook.这意味着我想将
c
更新为1
而不必使用类似useRef
挂钩的东西。
const [c, s] = useState<number>(0)
const f = () => {
s(1)
setTimeout(() => console.log(c), 600)
}
return (
<div
style={{ width: '100%', height: '100%', backgroundColor: 'black' }}
onMouseEnter={f}
>
test
</div>
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.