草庐IT

cancelAnimationFrame

全部标签

javascript - 使用requestAnimationFrame和cancelAnimationFrame时useEffect的执行顺序和内部清理逻辑是什么?

根据React文档,useEffect将在重新运行useEffect部分之前触发清理逻辑。Ifyoureffectreturnsafunction,Reactwillrunitwhenitistimetocleanup...ThereisnospecialcodeforhandlingupdatesbecauseuseEffecthandlesthembydefault.Itcleansupthepreviouseffectsbeforeapplyingthenexteffects...但是,当我在useEffect中使用requestAnimationFrame和cancelAnim