Created
March 2, 2024 11:12
-
-
Save AlemTuzlak/11d1b9aa8b5e21eb08af0a73763855e3 to your computer and use it in GitHub Desktop.
react-query adapter for remix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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