https://github.com/bentatum/redux-simplestorage
Seamless redux and localStorage
https://github.com/bentatum/redux-simplestorage
Last synced: about 2 months ago
JSON representation
Seamless redux and localStorage
- Host: GitHub
- URL: https://github.com/bentatum/redux-simplestorage
- Owner: bentatum
- Created: 2016-03-18T05:27:49.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2017-03-25T15:35:11.000Z (about 8 years ago)
- Last Synced: 2025-02-07T06:43:42.687Z (4 months ago)
- Language: JavaScript
- Homepage:
- Size: 37.1 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# redux-simplestorage
[](https://gemnasium.com/github.com/bentatum/redux-simplestorage)
[](http://standardjs.com/)
[](http://commitizen.github.io/cz-cli/)Use this to seamlessly store data in localStorage via redux actions.
## Installation
`npm i redux-simplestorage````javascript
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.```javascript
const STORE_SESSION = 'STORE_SESSION'
const SESSION = 'SESSION'export function storeSession(session) {
return {
type: STORE_SESSION,
storage: {
[SESSION]: session
}
}
}
```Later on...
```javascript
const session = localStorage.getItem(SESSION)
```[Demo](http://benjamintatum.com/redux-simplestorage)