Преглед на файлове

WIP: implement useSWRStatic in @growi/core

Yuki Takei преди 2 години
родител
ревизия
17235c06e0
променени са 2 файла, в които са добавени 8 реда и са изтрити 7 реда
  1. 1 0
      packages/core/src/swr/index.ts
  2. 7 7
      packages/core/src/swr/use-swr-static.ts

+ 1 - 0
packages/core/src/swr/index.ts

@@ -1 +1,2 @@
+export * from './use-swr-static';
 export * from './with-utils';

+ 7 - 7
apps/app/src/stores/use-static-swr.tsx → packages/core/src/swr/use-swr-static.ts

@@ -1,24 +1,24 @@
-import assert from 'assert';
-
 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,
+export function useSWRStatic<Data, Error>(key: Key): SWRResponse<Data, Error>;
+export function useSWRStatic<Data, Error>(key: Key, data: Data | undefined): SWRResponse<Data, Error>;
+export function useSWRStatic<Data, Error>(key: Key, data: Data | undefined,
   configuration: SWRConfiguration<Data, Error> | undefined): SWRResponse<Data, Error>;
 
-export function useStaticSWR<Data, Error>(
+export function useSWRStatic<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\'');
+  if (configuration?.fetcher != null) {
+    throw new Error("useSWRStatic does not support 'configuration.fetcher'");
+  }
 
   const { cache } = useSWRConfig();
   const swrResponse = useSWRImmutable(key, null, {