IndexedDB
wrapper that mimicslocalStorage
API
npm install local-db-storage
- If you want to use
IndexedDB
but don't want to deal with its complex API. - If you want to store more data than what
localStorage
supports but still want the same API. - The most popular library
localForage
(25k stars) is complex and unmaintained. - I've been consistent in maintaining
use-local-storage-state
(400k downloads per month) for the past 4 years.
import dbStorage from 'local-db-storage'
async function addTodo(todo): Promise<void> {
await dbStorage.setItem(todo.id, todo)
}
async function getTodo(id: string): Promise<Todo> {
await dbStorage.getItem<Todo>(id)
}
Like localStorage.getItem()
but async.
Like localStorage.setItem()
but async.
Note: It supports non-primitive values (ex: objects). It also supports circular references.
Like localStorage.removeItem()
but async.
Like localStorage.clear()
but async.
Creates a new DBStorage
instance.
import { DBStorage } from 'local-db-storage'
const dbStorage = new DBStorage('my-custom-db-storage')
await dbStorage.setItem('initial', 'hello world')
use-db
— React hook forIndexedDB
that uses this library and mimicssetState
API.use-local-storage-state
— React hook that persists data inlocalStorage
.use-session-storage-state
— React hook that persists data insessionStorage
.