An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

        

# redux-simplestorage

[![Dependency Status](https://gemnasium.com/badges/github.com/bentatum/redux-simplestorage.svg)](https://gemnasium.com/github.com/bentatum/redux-simplestorage)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](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)