Răsfoiți Sursa

imprv useSWRxPageAncestorsChildren

Taichi Masuyama 3 ani în urmă
părinte
comite
0b452e34e2
1 a modificat fișierele cu 6 adăugiri și 0 ștergeri
  1. 6 0
      packages/app/src/stores/page-listing.tsx

+ 6 - 0
packages/app/src/stores/page-listing.tsx

@@ -153,6 +153,9 @@ export const useSWRxPageAncestorsChildren = (
 ): SWRResponse<AncestorsChildrenResult, Error> => {
   const { data: termNumber } = usePageTreeTermManager();
 
+  const prevTermNumber = termNumber ? termNumber - 1 : 0;
+  const prevSWRRes = useSWRImmutable(path ? [`/page-listing/ancestors-children?path=${path}`, prevTermNumber] : null);
+
   return useSWRImmutable(
     path ? [`/page-listing/ancestors-children?path=${path}`, termNumber] : null,
     endpoint => apiv3Get(endpoint).then((response) => {
@@ -160,6 +163,9 @@ export const useSWRxPageAncestorsChildren = (
         ancestorsChildren: response.data.ancestorsChildren,
       };
     }),
+    {
+      fallbackData: prevSWRRes.data, // avoid data to be undefined due to the termNumber to change
+    }
   );
 };