Tiny wrapper around
IndexedDB
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
is bloated and unmaintained.
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. It supports non-primitive values like objects. It also supports circular references.
Like localStorage.removeItem()
but async.
Like localStorage.clear()
but async.
use-local-storage-state
— React hook that persists data inlocalStorage
.use-session-storage-state
— React hook that persists data insessionStorage
.