我正在寻找通过 setState 回调访问状态以外的其他方式(由于新的 experimental concurrent mode)
在 useCallback
依赖项数组中包含状态是否保证状态是最新的,如下例所示?
const [count, setCount] = useState(0);
const increment = useCallback(() => {
// Is count guaranteed to be the latest state here due to including count in the useCallback dependency array?
console.log(count);
setCount((count) => count + 1);
}, [count]);