2020.7.4-1 • Published 4 years ago

@grooveland/redux-storage v2020.7.4-1

Weekly downloads
-
License
AGPL-3.0
Repository
github
Last release
4 years ago

@grooveland/redux-storage

Middleware to record status changes (Redux) and store them in the browser storage

DEPENDENCIES

@grooveland/redux-storage depends on redux.

Usage

yarn add @grooveland/redux-storage

or

npm i --save @grooveland/redux-storage

Inside the file where your redux store is configured you must import the initializer

import { storage } from '@grooveland/redux-storage';

Once imported you must configure the middleware and the pre-load function

const [preload, storageMiddleware] = storage({ type: 'session', key: 'grooveland' });

Finally we only have to load the initial state of the application from the selected storage.

const initState = {
    ...preload(),
};

and then we register the middleware inside the store

const composedEnhancers = compose(storageMiddleware);
export const store = createStore(reducer, composedEnhancers);

The middleware registers all changes within our state and stores them in the selected storage.

API

Description of the properties available within the storage method

KeyTypeDefaultDescription
typeStorageSettingslocalType of storage used for data persistence
keystringnew Date().getTime()storage access key

StorageSettings

It only supports storage types such as local and session.