# redux-persistent-state-snapshot

> Redux middleware for making persistent state snapshots

Latest version **1.0.4** (published 2015-12-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install redux-persistent-state-snapshot
pnpm add redux-persistent-state-snapshot
yarn add redux-persistent-state-snapshot
bun add redux-persistent-state-snapshot
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2015-12-04 |
| First published | 2015-11-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Marco Garcia |
| Maintainers | marcoga |
| Keywords | redux, middleware, redux-middleware, flux |

## Links

- npm: https://www.npmjs.com/package/redux-persistent-state-snapshot
- Repository: https://github.com/Marcoga/redux-persistent-state-snapshot
- Issues: https://github.com/Marcoga/redux-persistent-state-snapshot/issues
- npm.io page: https://npm.io/package/redux-persistent-state-snapshot

## Alternatives

- [@reckona/mreact-store](https://npm.io/package/@reckona/mreact-store.md) — 976 weekly downloads
- [regular-state](https://npm.io/package/regular-state.md) — 410 weekly downloads
- [@pacote/flux-actions](https://npm.io/package/@pacote/flux-actions.md) — 65 weekly downloads
- [@pilotlab/lux-debug](https://npm.io/package/@pilotlab/lux-debug.md) — 39 weekly downloads
- [vue-persist-state](https://npm.io/package/vue-persist-state.md) — 19 weekly downloads

## Recent versions

- 1.0.4 (latest) — 2015-12-04
- 1.0.3 — 2015-12-04
- 1.0.2 — 2015-11-10
- 1.0.1 — 2015-11-09
- 1.0.0 — 2015-11-09

## README

Redux Persistent State Snapshot
====
[Middleware](http://rackt.github.io/redux/docs/advanced/Middleware.html) to persist your state in a Redux app.

```js
npm install --save redux-persistent-state-snapshot
```
# Motivation
Persist a part (for example your UI State) of your State tree.

# Usage
```js
import createPersistentStateSnapshot from 'redux-persistent-state-snapshot';

const reduxStateSnapshot = 'reduxStateSnapshot';

const persistentStateSnaphot = createPersistentStateSnapshot({
  //key where your state will be mounted
  mountAt: reduxStateSnapshot,
  //select the state you want to persist
  selector: state => ({
    orderBy: state.orderBy,
    filters: state.filters
  })
});

//apply the middleware
const finalCreateStore = compose(
  applyMiddleware(thunk, persistentStateSnaphot),
)(createStore);

export default function configureStore(initialState = {}) {
  //the default serialization is JSON.stringify --> so use JSON.parse to deserialize
  const stateSnapshot = JSON.parse(
    //the default persistent storage is localStorage
    localStorage
      .getItem(reduxStateSnapshot)
  );

  const finalInitialState = {
    ...initialState,
    ...stateSnapshot
  };

  //one way to inject your saved Data when the application is mounted is to pass it as the initialState to the store
  const store = finalCreateStore(rootReducer, finalInitialState);

  //but you could also create an action on the root component on componentWillMount...


  return store;
}
```

---
_Source: https://npm.io/package/redux-persistent-state-snapshot · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
