|
@@ -14,11 +14,10 @@ import { IPageTagsInfo } from '../interfaces/tag';
|
|
|
|
|
|
|
|
import { useCurrentPageId } from './context';
|
|
import { useCurrentPageId } from './context';
|
|
|
|
|
|
|
|
-export const useSWRxPage = (pageId?: string|null, shareLinkId?: string, initialData?: IPageHasId): SWRResponse<IPageHasId, Error> => {
|
|
|
|
|
|
|
+export const useSWRxPage = (pageId?: string|null, shareLinkId?: string): SWRResponse<IPageHasId, Error> => {
|
|
|
return useSWR<IPageHasId, Error>(
|
|
return useSWR<IPageHasId, Error>(
|
|
|
pageId != null ? ['/page', pageId, shareLinkId] : null,
|
|
pageId != null ? ['/page', pageId, shareLinkId] : null,
|
|
|
(endpoint, pageId, shareLinkId) => apiv3Get(endpoint, { pageId, shareLinkId }).then(result => result.data.page),
|
|
(endpoint, pageId, shareLinkId) => apiv3Get(endpoint, { pageId, shareLinkId }).then(result => result.data.page),
|
|
|
- { fallbackData: initialData },
|
|
|
|
|
);
|
|
);
|
|
|
};
|
|
};
|
|
|
|
|
|
|
@@ -32,7 +31,15 @@ export const useSWRxPageByPath = (path?: string): SWRResponse<IPageHasId, Error>
|
|
|
export const useSWRxCurrentPage = (shareLinkId?: string, initialData?: IPageHasId): SWRResponse<IPageHasId, Error> => {
|
|
export const useSWRxCurrentPage = (shareLinkId?: string, initialData?: IPageHasId): SWRResponse<IPageHasId, Error> => {
|
|
|
const { data: currentPageId } = useCurrentPageId();
|
|
const { data: currentPageId } = useCurrentPageId();
|
|
|
|
|
|
|
|
- return useSWRxPage(currentPageId, shareLinkId, initialData);
|
|
|
|
|
|
|
+ const swrResult = useSWRxPage(currentPageId, shareLinkId);
|
|
|
|
|
+
|
|
|
|
|
+ // use mutate because fallbackData does not work
|
|
|
|
|
+ // see: https://github.com/weseek/growi/commit/5038473e8d6028c9c91310e374a7b5f48b921a15
|
|
|
|
|
+ if (initialData != null) {
|
|
|
|
|
+ swrResult.mutate(initialData);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return swrResult;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
|