Simple IndexedDB driver example (using idb-keyval)
psychedelicious opened this issue · 0 comments
psychedelicious commented
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,
})