Yuki Takei 2 лет назад
Родитель
Сommit
959a1a483c
1 измененных файлов с 5 добавлено и 3 удалено
  1. 5 3
      packages/core/src/swr/use-swr-static.ts

+ 5 - 3
packages/core/src/swr/use-swr-static.ts

@@ -23,12 +23,14 @@ export function useSWRStatic<Data, Error>(
   const { cache } = useSWRConfig();
   const { cache } = useSWRConfig();
   const swrResponse = useSWRImmutable(key, null, {
   const swrResponse = useSWRImmutable(key, null, {
     ...configuration,
     ...configuration,
-    fallbackData: configuration?.fallbackData ?? cache.get(key)?.data,
+    fallbackData: configuration?.fallbackData ?? (
+      key != null ? cache.get(key?.toString())?.data : undefined
+    ),
   });
   });
 
 
   // write data to cache directly
   // write data to cache directly
-  if (data !== undefined) {
-    cache.set(key, { ...cache.get(key), data });
+  if (key != null && data !== undefined) {
+    cache.set(key.toString(), { ...cache.get(key.toString()), data });
   }
   }
 
 
   return swrResponse;
   return swrResponse;