Jelajahi Sumber

imprv useSWRxPageAncestorsChildren

Taichi Masuyama 3 tahun lalu
induk
melakukan
0b452e34e2
1 mengubah file dengan 6 tambahan dan 0 penghapusan
  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
+    }
   );
 };