Socket
Socket
Sign inDemoInstall

redux-persist

Package Overview
Dependencies
1
Maintainers
2
Versions
186
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 5.6.8 to 5.6.9

4

package.json
{
"name": "redux-persist",
"version": "5.6.8",
"version": "5.6.9",
"description": "persist and rehydrate redux stores",

@@ -30,3 +30,3 @@ "main": "lib/index.js",

"src/**/*.js": [
"prettier --no-semi --single-quote --trailing-comma --parser=flow --write",
"prettier --write",
"git add"

@@ -33,0 +33,0 @@ ]

@@ -7,7 +7,2 @@ # Redux Persist

Redux Persist takes your redux state object and saves it to persisted storage. On app launch, it retrieves this persisted state and saves it back to redux.
**Note:** These instructions are for redux-persist v5. For a list of breaking changes between v4 and v5, see our [migration guide](./docs/MigrationGuide-v5.md).
[v4](https://github.com/rt2zz/redux-persist/tree/v4) will be supported for the forseeable future, and if it works well for your use case you are encouraged to stay on v4.
## Quickstart

@@ -30,3 +25,3 @@ `npm install redux-persist`

import { persistStore, persistReducer } from 'redux-persist'
import storage from 'redux-persist/lib/storage'
import storage from 'redux-persist/lib/storage' // defaults to localStorage for web and AsyncStorage for react-native

@@ -37,3 +32,3 @@ import rootReducer from './reducers'

key: 'root',
storage: storage,
storage,
}

@@ -53,12 +48,6 @@

```js
import React from 'react'
import { Provider } from 'react-redux'
import { PersistGate } from 'redux-persist/lib/integration/react'
import { PersistGate } from 'redux-persist/integration/react'
import configureStore from './store/configureStore'
let { store, persistor } = configureStore()
// ... normal setup, create store and persistor, import components etc.
// import your necessary custom components.
import { RootComponent } from './components'
const App = () => {

@@ -73,4 +62,2 @@ return (

};
export default App
```

@@ -99,29 +86,29 @@

- the persistor object is returned by persistStore with the following methods:
- `.purge(keys)`
- `.purge()`
- purges state from disk and returns a promise
- `flush()`
- `.flush()`
- immediately writes all pending state to disk and returns a promise
- `pause()`
- `.pause()`
- pauses persistence
- `persist()`
- `.persist()`
- resumes persistence
## State Reconciler
State reconcilers define how incoming persisted state is merged in with existing default state. It is critical to choose the right state reconciler for your state shape. There are three options that ship out of the box, lets look at how each operates:
State reconcilers define how incoming state is merged in with initial state. It is critical to choose the right state reconciler for your state. There are three options that ship out of the box, lets look at how each operates:
1. hardSet (`import hardSet from 'redux-persist/lib/stateReconciler/hardSet'`)
1. **hardSet** (`import hardSet from 'redux-persist/lib/stateReconciler/hardSet'`)
This will hard set incoming state. This can be desirable in some cases where persistReducer is nested deeper in your reducer tree, or if you do not rely on initialState in your reducer.
- **INCOMING STATE**: `{ foo: incomingFoo }`
- **INITIAL STATE**: `{ foo: initialFoo, bar: initialBar }`
- **RECONCILED STATE**: `{ foo: incomingFoo }` // note bar has been dropped
2. autoMergeLevel1 (default)
- **incoming state**: `{ foo: incomingFoo }`
- **initial state**: `{ foo: initialFoo, bar: initialBar }`
- **reconciled state**: `{ foo: incomingFoo }` // note bar has been dropped
2. **autoMergeLevel1** (default)
This will auto merge one level deep. Auto merge means if the some piece of substate was modified by your reducer during the REHYDRATE action, it will skip this piece of state. Level 1 means it will shallow merge 1 level deep.
- **INCOMING STATE**: `{ foo: incomingFoo }`
- **INITIAL STATE**: `{ foo: initialFoo, bar: initialBar }`
- **RECONCILED STATE**: `{ foo: incomingFoo, bar: initialBar }`
3. autoMergeLevel2
- **incoming state**: `{ foo: incomingFoo }`
- **initial state**: `{ foo: initialFoo, bar: initialBar }`
- **reconciled state**: `{ foo: incomingFoo, bar: initialBar }` // note incomingFoo overwrites initialFoo
3. **autoMergeLevel2** (`import autoMergeLevel2 from 'redux-persist/lib/stateReconciler/autoMergeLevel2'`)
This acts just like autoMergeLevel1, except it shallow merges two levels
- **INCOMING STATE**: `{ foo: incomingFoo }`
- **INITIAL STATE**: `{ foo: initialFoo, bar: initialBar }`
- **RECONCILED STATE**: `{ foo: mergedFoo, bar: initialBar }`
- **incoming state**: `{ foo: incomingFoo }`
- **initial state**: `{ foo: initialFoo, bar: initialBar }`
- **reconciled state**: `{ foo: mergedFoo, bar: initialBar }` // note: initialFoo and incomingFoo are shallow merged

@@ -158,3 +145,3 @@ #### Example

## Nested Persists
Nested persist can be useful for a variety of reasons including different storage adapters, code splitting, or deep filtering. For example blacklist and whitelist only work one level deep, but we can use a nested persist to blacklist a deep value:
Nested persist can be useful for including different storage adapters, code splitting, or deep filtering. For example while blacklist and whitelist only work one level deep, but we can use a nested persist to blacklist a deeper value:
```js

@@ -193,3 +180,2 @@ import { combineReducers } from 'redux'

## Transforms
Transforms allow you to customize the state object that gets persisted and rehydrated.

@@ -227,10 +213,10 @@

The createTransform function takes three parameters.
1. A function that gets called right before state is persisted.
2. A function that gets called right before state is rehydrated.
3. A config object.
1. An "inbound" function that gets called right before state is persisted.
2. An "outbound" function that gets called right before state is rehydrated.
3. Config.
## Storage Engines
- **localStorage** `import storage from 'redux-persist/lib/storage'`
- **sessionStorage** `import sessionStorage from 'redux-persist/lib/storage/session'`
- **AsyncStorage** react-native `import storage from 'redux-persist/lib/storage'`
- **sessionStorage** `import storageSession from 'redux-persist/lib/storage/session'`
- **AsyncStorage** react-native `import { AsyncStorage } from 'react-native'`
- **[localForage](https://github.com/mozilla/localForage)** recommended for web

@@ -237,0 +223,0 @@ - **[electron storage](https://github.com/psperber/redux-persist-electron-storage)** Electron support via [electron store](https://github.com/sindresorhus/electron-store)

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc