Просмотр исходного кода

replace useStaticSWR with useSWRStatic

Yuki Takei 2 лет назад
Родитель
Сommit
40e771d731

+ 6 - 0
apps/app/src/stores/use-static-swr.ts

@@ -0,0 +1,6 @@
+import { useSWRStatic } from '@growi/core/dist/swr';
+
+/**
+ * @deprecated Import { uswSWRStatic } from '@growi/core/dist/swr' instead.
+ */
+export const useStaticSWR = useSWRStatic;

+ 2 - 4
packages/editor/src/stores/codemirror-editor.ts

@@ -3,14 +3,12 @@ import { useMemo } from 'react';
 import { type Extension } from '@codemirror/state';
 import { scrollPastEnd } from '@codemirror/view';
 import {
-  type SWRResponseWithUtils, withUtils,
+  type SWRResponseWithUtils, withUtils, useSWRStatic,
 } from '@growi/core/dist/swr';
 
 import type { UseCodeMirrorEditor, UseCodeMirrorEditorResponse } from '../services';
 import { useCodeMirrorEditor } from '../services';
 
-import { useStaticSWR } from './use-static-swr';
-
 const defaultExtensionsMain: Extension[] = [
   scrollPastEnd(),
 ];
@@ -30,7 +28,7 @@ export const useCodeMirrorEditorMain = (container?: HTMLDivElement | null): SWRR
 
   const states = useCodeMirrorEditor(props);
 
-  const swrResponse = useStaticSWR('codeMirrorEditorMain', container != null ? states : undefined);
+  const swrResponse = useSWRStatic('codeMirrorEditorMain', container != null ? states : undefined);
 
   return withUtils(swrResponse, {
     // impl something

+ 0 - 33
packages/editor/src/stores/use-static-swr.tsx

@@ -1,33 +0,0 @@
-import {
-  Key, SWRConfiguration, SWRResponse, useSWRConfig,
-} from 'swr';
-import useSWRImmutable from 'swr/immutable';
-
-
-export function useStaticSWR<Data, Error>(key: Key): SWRResponse<Data, Error>;
-export function useStaticSWR<Data, Error>(key: Key, data: Data | undefined): SWRResponse<Data, Error>;
-export function useStaticSWR<Data, Error>(key: Key, data: Data | undefined,
-  configuration: SWRConfiguration<Data, Error> | undefined): SWRResponse<Data, Error>;
-
-export function useStaticSWR<Data, Error>(
-    ...args: readonly [Key]
-    | readonly [Key, Data | undefined]
-    | readonly [Key, Data | undefined, SWRConfiguration<Data, Error> | undefined]
-): SWRResponse<Data, Error> {
-  const [key, data, configuration] = args;
-
-  // assert.notStrictEqual(configuration?.fetcher, null, 'useStaticSWR does not support \'configuration.fetcher\'');
-
-  const { cache } = useSWRConfig();
-  const swrResponse = useSWRImmutable(key, null, {
-    ...configuration,
-    fallbackData: configuration?.fallbackData ?? cache.get(key)?.data,
-  });
-
-  // write data to cache directly
-  if (data !== undefined) {
-    cache.set(key, { ...cache.get(key), data });
-  }
-
-  return swrResponse;
-}