Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple IndexedDB driver example (using idb-keyval) #9

Open
psychedelicious opened this issue Nov 13, 2023 · 0 comments
Open

Simple IndexedDB driver example (using idb-keyval) #9

psychedelicious opened this issue Nov 13, 2023 · 0 comments
Labels

Comments

@psychedelicious
Copy link
Contributor

psychedelicious commented Nov 13, 2023

This is a trivial example, but I figured I'd share anyways.

Here's a simple storage driver using idb-keyval, a minimal library that wraps IndexedDB with a simple key-value interface:

import { createStore, get, set } from 'idb-keyval';
import { Driver } from 'redux-remember';

// Create a custom idb-keyval store (just needed to customize the name, else it's awkwardly named "keyval-store/keyval")
const idbKeyValStore = createStore('my-database', 'my-store');

// Create redux-remember driver, wrapping idb-keyval
const idbKeyValDriver: Driver = {
  getItem: (key) => get(key, idbKeyValStore),
  setItem: (key, value) => set(key, value, idbKeyValStore),
};

// Usage
rememberEnhancer(idbKeyValDriver, rememberedKeys, {
  serialize,
  unserialize,
})
@zewish zewish added the docs label Nov 15, 2023
@zewish zewish changed the title Simple IndexedDB driver example Simple IndexedDB driver example (using idb-keyval) Nov 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants