Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save AlemTuzlak/11d1b9aa8b5e21eb08af0a73763855e3 to your computer and use it in GitHub Desktop.
Save AlemTuzlak/11d1b9aa8b5e21eb08af0a73763855e3 to your computer and use it in GitHub Desktop.
react-query adapter for remix
import { QueryClient } from "@tanstack/react-query";
import { CacheAdapter, createCacheAdapter } from "remix-client-cache";
export const queryClient = new QueryClient({
defaultOptions: {
queries: {
staleTime: 1000 * 60 * 5,
},
},
});
class ReactQueryAdapter implements CacheAdapter {
async getItem(key: string) {
return queryClient.getQueryData([key]);
}
async setItem(key: string, value: string) {
return queryClient.setQueryData([key], value);
}
async removeItem(key: string) {
return queryClient.removeQueries({
queryKey: [key],
});
}
}
const { adapter } = createCacheAdapter(() => new ReactQueryAdapter());
export const reactQueryAdapter = adapter;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment