我有一个州,最初是undefined
.在完成某些操作之后,我正在更新该状态,并且我需要在该状态更新后立即运行一些操作.但是,由于该状态经常更改,所以我不想使用useEffect
CUZ,也不希望每次状态更改时都执行代码.只是为了第一次更新.我怎样才能做到这一点呢?以下是演示代码
const [annotations,setAnnotations] =useState()
// A bunch of changes and after some time, called setAnnotations(value)
useEffect(()=> {
// here I need to do something. But, don't have the latest annotations.
// I only need to do // something only for the first time
},[])