indexDB-storage.ts 530 B

1234567891011121314151617181920
  1. import { StateStorage } from "zustand/middleware";
  2. import { get, set, del } from "idb-keyval";
  3. class IndexDBStorage implements StateStorage {
  4. constructor() {}
  5. public async getItem(name: string): Promise<string | null> {
  6. return (await get(name)) || localStorage.getItem(name);
  7. }
  8. public async setItem(name: string, value: string): Promise<void> {
  9. await set(name, value);
  10. }
  11. public async removeItem(name: string): Promise<void> {
  12. await del(name);
  13. }
  14. }
  15. export const indexDBStorage = new IndexDBStorage();