1.0.5 • Published 7 years ago
redux-simplestorage v1.0.5
redux-simplestorage
Use this to seamlessly store data in localStorage via redux actions.
Installation
npm i redux-simplestorage
import { createStore, applyMiddleware } from 'redux'
import storageMiddleware from 'redux-simplestorage'
const reduxStore = applyMiddleware([storageMiddleware])(createStore)
Usage
To store data in localStorage via redux action, simply include a storage key. The storage value is an object whose keys will be stored in localStorage.
const STORE_SESSION = 'STORE_SESSION'
const SESSION = 'SESSION'
export function storeSession(session) {
return {
type: STORE_SESSION,
storage: {
[SESSION]: session
}
}
}
Later on...
const session = localStorage.getItem(SESSION)