Skip to content

Commit 936d223

Browse files
authored
fix(clerk-js): Add optional resourceId to useFetch hook (#5536)
1 parent 2cceeba commit 936d223

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

.changeset/lucky-emus-share.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@clerk/clerk-js': patch
3+
---
4+
5+
Add optional `resourceId` to `useFetch` hook

packages/clerk-js/src/ui/hooks/useFetch.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export const useCache = <K = any, V = any>(
7979
* @param fetcher If fetcher is undefined no action will be performed
8080
* @param params
8181
* @param options
82+
* @param resourceId
8283
*/
8384
export const useFetch = <K, T>(
8485
fetcher: ((...args: any) => Promise<T>) | undefined,
@@ -88,8 +89,10 @@ export const useFetch = <K, T>(
8889
onSuccess?: (data: T) => void;
8990
staleTime?: number;
9091
},
92+
resourceId?: string,
9193
) => {
92-
const { subscribeCache, getCache, setCache, clearCache } = useCache<K, T>(params);
94+
const cacheKey = { resourceId, params };
95+
const { subscribeCache, getCache, setCache, clearCache } = useCache<typeof cacheKey, T>(cacheKey);
9396
const [revalidationCounter, setRevalidationCounter] = useState(0);
9497

9598
const staleTime = options?.staleTime ?? 1000 * 60 * 2; //cache for 2 minutes by default

0 commit comments

Comments
 (0)