Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@piotr-cz/redux-persist-idb-storage

piotr-cz12.9kMIT1.1.3TypeScript support: included

Redux Persist adapter for IndexedDB storage

redux, redux-persist, IndexedDB, idb

readme

Redux Persist adapter for IndexedDB storage

Storage adapter to use IndexedDB via idb v3 with redux-persist ripped from idb v3 docs > Examples section

Installation

Using npm:

npm install --save @piotr-cz/redux-persist-idb-storage

or Yarn:

yarn add @piotr-cz/redux-persist-idb-storage

Requirements

Setup

Import the storage and include it in persistConfig when creating Redux store:

// configureStore.js

// Using CommonJS modules
import createIdbStorage from '@piotr-cz/redux-persist-idb-storage'

// Or using ES6 modules
import createIdbStorage from '@piotr-cz/redux-persist-idb-storage/src'

const persistConfig = {
  key: 'root',
  storage: createIdbStorage({name: 'myApp', storeName: 'keyval'}),
  serialize: false, // Data serialization is not required and disabling it allows you to inspect storage value in DevTools
}

// ...

Server-Side Rendering

When using Server-Side Rendering (SSR), indexedDB won't be available in the environment.

In this case you may use feature detection with a fallback to use default redux-persist storage (which resolves to noop functions):

// configureStore.js

// Redux Persist storage
import defaultStorage from 'redux-persist/lib/storage'

// IndexedDB storage
import createIdbStorage from '@piotr-cz/redux-persist-idb-storage/src'

const persistConfig = {
  key: 'root',
  storage: globalThis.indexedDB ? createIdbStorage({name: 'myApp', storeName: 'keyval'}) : defaultStorage,
  serialize: false, 
}

Options

See idb API

  • name (optional): IndexedDB Database name. Defaults to 'keyval-store'.
  • storeName (optional): IndexedDB Store name. Defaults to 'keyval'.
  • version (optional): Schema version. Defaults to 1.
  • upgradeCallback (optional): Defaults to upgradeDb => upgradeDb.createObjectStore(options.storeName).

Notes

  • idb dependency is locked to version ^3.0.0 as 4+ uses proxies which are not supported in older browsers
  • credits go to idb authors

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

Unreleased

1.1.3 - 2022-02-03

Fixed

  • Types

1.1.2 - 2021-05-06

Fixed

  • Use readonly transaction mode in getAll method

1.1.1 - 2020-11-20

Security

  • Updated dev dependencies

1.1.0 - 2020-06-09

Changed

  • Disabled output compression
  • Change to TypeScript
  • Bumped build dependencies

[1.0.2] - 2019-09-20

Changed

  • Switched build script to microbundle

1.0.1 - 2019-09-16

Changed

  • Minor tweaks to meta files

1.0.0 - 2019-04-11

Added

  • Initial release