Browse Source

split useEffect

reiji-h 2 years ago
parent
commit
df55bef492
1 changed files with 8 additions and 3 deletions
  1. 8 3
      apps/app/src/components/Common/PagePathNav/PagePathNav.tsx

+ 8 - 3
apps/app/src/components/Common/PagePathNav/PagePathNav.tsx

@@ -125,19 +125,24 @@ export const PagePathNavSticky = (props: PagePathNavStickyProps): JSX.Element =>
   const [navMaxWidth, setNavMaxWidth] = useState<number | undefined>();
   const [navMaxWidth, setNavMaxWidth] = useState<number | undefined>();
 
 
   useEffect(() => {
   useEffect(() => {
+    if (pageControlsX == null || pagePathNavRef.current == null || sidebarWidth == null) {
+      return;
+    }
+    setNavMaxWidth(pageControlsX - pagePathNavRef.current.getBoundingClientRect().x - 10);
+  }, [pageControlsX, pagePathNavRef, sidebarWidth]);
 
 
+  useEffect(() => {
     // wait for the end of the animation of the opening and closing of the sidebar
     // wait for the end of the animation of the opening and closing of the sidebar
     const timeout = setTimeout(() => {
     const timeout = setTimeout(() => {
-      if (pageControlsX == null || pagePathNavRef.current == null || sidebarWidth == null || sidebarMode == null) {
+      if (pageControlsX == null || pagePathNavRef.current == null || sidebarMode == null) {
         return;
         return;
       }
       }
       setNavMaxWidth(pageControlsX - pagePathNavRef.current.getBoundingClientRect().x - 10);
       setNavMaxWidth(pageControlsX - pagePathNavRef.current.getBoundingClientRect().x - 10);
     }, 200);
     }, 200);
-
     return () => {
     return () => {
       clearTimeout(timeout);
       clearTimeout(timeout);
     };
     };
-  }, [pageControlsX, pagePathNavRef, sidebarWidth, sidebarMode]);
+  }, [pageControlsX, pagePathNavRef, sidebarMode]);
 
 
   return (
   return (
     // Controlling pointer-events
     // Controlling pointer-events