const [count, setCount]=useState(0);
useEffect(()=>{
console.log("count inside hook is ", count);
},[count]);
if(count<10)
setCount(count+1); // setCount(count=>count+1)
Run Code Online (Sandbox Code Playgroud)
我有这段代码,我期望每个计数都有控制台,但我只能看到 count=10 的控制台日志。
我的理解是,给定一个依赖数组,当其中的对象发生更改时,必须调用 useEffect,但这里不会发生这种情况。有人可以解释为什么会发生这种情况吗?
谢谢!