hi 老师好,想问下为什么在useffect中return的方法,会在卸载时调用呢
来源:8-2 ⽤useRef实现useDocumentTitle - useRef与Hook 闭包详解(下)

weixin_慕码人320477
2021-05-01
hi 老师好,想问下为什么在useffect中return的方法,会在卸载时调用呢
useEffect(() => {
return () => {
if (!keepOnUnmount) {
document.title = oldTitle;
}
};
}, [keepOnUnmount, oldTitle]);
写回答
1回答
-
Nolan
2021-05-02
这个没有为什么,设计React的人就是这么设计的
10
相似问题