Files
xLog/src/lib/persister.client.ts
T
2022-08-06 18:49:04 +01:00

24 lines
608 B
TypeScript

import { get, set, del } from "idb-keyval"
import {
PersistedClient,
Persister,
} from "@tanstack/react-query-persist-client"
/**
* Creates an Indexed DB persister
* @see https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API
*/
export function createIDBPersister(idbValidKey: IDBValidKey = "reactQuery") {
return {
persistClient: async (client: PersistedClient) => {
set(idbValidKey, client)
},
restoreClient: async () => {
return await get<PersistedClient>(idbValidKey)
},
removeClient: async () => {
await del(idbValidKey)
},
} as Persister
}