1.0.2 • Published 6 years ago

redux-persist-webextension-storage v1.0.2

Weekly downloads
816
License
MIT
Repository
github
Last release
6 years ago

redux-persist-webextension-storage

A WebExtension Storage storage engine for redux-persist.

Installation

Add the redux-persist-webextension-storage NPM package via NPM or Yarn:

$ yarn add redux-persist-webextension-storage

Usage

There are separate storage engines for local storage and sync storage. Import the one you need, or both, and pass them as storage engines when configuring your store.

// configureStore.js

import { combineReducers, createStore } from 'redux'
import { persistStore, persistReducer } from 'redux-persist'
import { localStorage, syncStorage } from 'redux-persist-webextension-storage'

import localStorageReducer from './localStorageReducer';
import syncStorageReducer from './syncStorageReducer';

const localStorageConfig = {
  key: 'localStorage',
  storage: syncStorage,
}

const syncStorageConfig = {
  key: 'syncStorage',
  storage: syncStorage,
}

// Persist each of the storage areas under different keys and with different storage engines.
const rootReducer = combineReducers({
  localStorage: persistReducer(localStorageConfig, localStorageReducer),
  syncStorage: persistReducer(syncStorageConfig, syncStorageReducer),
})

export default () => {
  const store = createStore(rootReducer)
  const persistor = persistStore(store)
  return { store, persistor }
}