Skip to content

Instantly share code, notes, and snippets.

View stevebauman's full-sized avatar

Steve Bauman stevebauman

View GitHub Profile
@johannschopplich
johannschopplich / storage.ts
Last active June 27, 2024 15:27
IndexedDB storage wrapper for VueUse
import { useStorageAsync } from "@vueuse/core";
import { get, set, del } from "idb-keyval";
export const STORAGE_KEY_PREFIX = "app.session.";
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function useIdbStorage<T = any>(key: string, initialValue: T) {
return useStorageAsync(`${STORAGE_KEY_PREFIX}${key}`, initialValue, {
async getItem(key: string) {
return (await get<string>(key)) ?? null;