https://github.com/pirosikick/redux-save-state
A redux middleware which saves the state to localStorage
https://github.com/pirosikick/redux-save-state
Last synced: about 2 months ago
JSON representation
A redux middleware which saves the state to localStorage
- Host: GitHub
- URL: https://github.com/pirosikick/redux-save-state
- Owner: pirosikick
- Created: 2015-11-04T12:49:02.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-11-09T08:58:52.000Z (over 9 years ago)
- Last Synced: 2025-04-03T21:39:37.871Z (2 months ago)
- Language: JavaScript
- Homepage:
- Size: 133 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[](http://badge.fury.io/js/redux-save-state)
[](https://david-dm.org/pirosikick/redux-save-state)
[](https://travis-ci.org/pirosikick/redux-save-state)redux-save-state
=================A redux middleware which saves a snapshot of the state to localStorage.
## Usage
### Example
```javascript
import {createStore, applyMiddleware} from "redux";
import saveState from "redux-save-state/localStorage";
import combinedReducers from "./reducer";const createStoreWithMiddlewares
= applyMiddleware(saveState('appState'))(createStore);
const store = createStoreWithMiddlewares(combinedReducers);// In React Component
store.dispatch(action);console.log(localStorage.appState); // state as JSON string
```### Interface
```javascript
import saveState from "redux-save-state/localStorage";const key = "some_key_string";
const options = { ... };
const middleware = saveState(key, options);
```#### `key` : String
Required. The key in localStorage to save state.
#### `options.filter`: Function(state: object) => object
default `state => state`.
Saves the value returned by `filter` function.#### `options.debounce`: Number
default 0.
Delays setting the state to localStorage until `debounce` milliseconds have elapsed since the last time the action was dispatched.
See also [_.debounce](https://lodash.com/docs#debounce).#### `options.callback`: Function(store) => any
## License
[MIT](http://pirosikick.mit-license.org/)