Skip to content

Instantly share code, notes, and snippets.

@isocroft
Created February 26, 2024 20:32
Show Gist options
  • Save isocroft/672e5ca2e73114b58ed78366929643be to your computer and use it in GitHub Desktop.
Save isocroft/672e5ca2e73114b58ed78366929643be to your computer and use it in GitHub Desktop.
A custom ReactJS/NextJS hook based on @tanstack/react-query that queries the cache for the contents at a given query key
import { useQueryClient } from "@tanstack/react-query";
export function useReactQueryCache<D, E>(queryKey: unknown[] = []) {
const queryClient = useQueryClient();
const queryCache = queryClient.getQueryCache();
return queryCache.find<D, E>(queryKey);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment