- 9 点 50 到公司
- 苹果醋中的醋酸可帮助改善身体的新陈代谢。
- 公司很忙。。。
- 注册了 cc 的 https://sorrycc.com 。等待通过
- 看到一段很有意思的代码, useLayoutEffect 放在 if 中执行,原因是这段代码只在浏览器环境运行
https://github1s.com/reactjs/react.dev/blob/HEAD/src/components/Layout/Sidebar/SidebarRouteTree.tsx#L39-L58
if (typeof window !== 'undefined') {
// eslint-disable-next-line react-hooks/rules-of-hooks
useLayoutEffect(() => {
const wasExpanded = isExpandedRef.current;
if (wasExpanded === isExpanded) {
return;
}
isExpandedRef.current = isExpanded;
if (ref.current !== null) {
const node: HTMLDivElement = ref.current;
node.style.pointerEvents = 'none';
if (timeoutRef.current !== null) {
window.clearTimeout(timeoutRef.current);
}
timeoutRef.current = window.setTimeout(() => {
node.style.pointerEvents = '';
}, duration + 100);
}
});
}
- 自定义实现useEvent
export function useEvent(fn: any): any {
const ref = useRef(null);
useInsertionEffect(() => {
ref.current = fn;
}, [fn]);
return useCallback((...args: any) => {
const f = ref.current!;
// @ts-ignore
return f(...args);
}, []);
}