Ver Fonte

migrate to SWR v2

Yuki Takei há 3 anos atrás
pai
commit
be59f71ef7

+ 4 - 4
packages/app/src/stores/ui.tsx

@@ -199,8 +199,8 @@ export const useIsDeviceSmallerThanMd = (): SWRResponse<boolean, Error> => {
       const mql = addBreakpointListener(Breakpoint.MD, mdOrAvobeHandler);
       const mql = addBreakpointListener(Breakpoint.MD, mdOrAvobeHandler);
 
 
       // initialize
       // initialize
-      if (cache.get(key) == null) {
-        mutate(key, !mql.matches);
+      if (cache.get(key)?.data == null) {
+        cache.set(key, { ...cache.get(key), data: !mql.matches });
       }
       }
 
 
       return () => {
       return () => {
@@ -227,8 +227,8 @@ export const useIsDeviceSmallerThanLg = (): SWRResponse<boolean, Error> => {
       const mql = addBreakpointListener(Breakpoint.LG, lgOrAvobeHandler);
       const mql = addBreakpointListener(Breakpoint.LG, lgOrAvobeHandler);
 
 
       // initialize
       // initialize
-      if (cache.get(key) == null) {
-        mutate(key, !mql.matches);
+      if (cache.get(key)?.data == null) {
+        cache.set(key, { ...cache.get(key), data: !mql.matches });
       }
       }
 
 
       return () => {
       return () => {

+ 1 - 1
packages/app/src/stores/use-context-swr.tsx

@@ -23,7 +23,7 @@ export function useContextSWR<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),
+    fallbackData: configuration?.fallbackData ?? cache.get(key)?.data,
   });
   });
 
 
   // write data to cache directly
   // write data to cache directly