Skip to content

Commit

Permalink
feat: accept ref as key
Browse files Browse the repository at this point in the history
  • Loading branch information
edumudu committed Aug 25, 2022
1 parent d52dbad commit 7b3d793
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/composables/swr/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const useSWR = <Data = any, Error = any>(
onError,
} = mergedConfig;

const { key, args: fetcherArgs } = toRefs(toReactive(computed(() => serializeKey(_key))));
const { key, args: fetcherArgs } = toRefs(toReactive(computed(() => serializeKey(unref(_key)))));
const fallbackValue = fallbackData === undefined ? fallback?.[key.value] : fallbackData;

const valueInCache = computed(() => cacheProvider.get(key.value));
Expand Down
4 changes: 2 additions & 2 deletions lib/types/lib.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Ref } from 'vue';
import type { DeepMaybeRef, MaybeRef } from '@/types/generics';

export type KeyArguments =
| string
Expand All @@ -9,7 +9,7 @@ export type KeyArguments =
| false;

export type Key = KeyArguments | (() => KeyArguments);
export type SWRKey = Key;
export type SWRKey = MaybeRef<Key>;
export type SWRFetcher<Data> =
| ((...args: any[]) => Promise<Data> | Data)
| (() => Promise<Data> | Data);
Expand Down

0 comments on commit 7b3d793

Please sign in to comment.