2024.1.15

  1. 9 点 50 到公司
  2. 苹果醋中的醋酸可帮助改善身体的新陈代谢。
  3. 公司很忙。。。
  4. 注册了 cc 的 https://sorrycc.com。等待通过
  5. 看到一段很有意思的代码, 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);
      }
    });
  }
  1. 自定义实现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);
  }, []);
}
posted @ 2024-01-15 19:04  被咯苏州  阅读(7)  评论(0编辑  收藏  举报