> For the complete documentation index, see [llms.txt](https://rematch.gitbook.io/handbook/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://rematch.gitbook.io/handbook/cha-jian/rematch-persist.md).

# Rematch Persist

当前 Rematch 依赖 Redux-Persist v5 版本插件。

使用 local  storage 选项提供简单的 redux 状态持久化。

![](https://3022960371-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LCqMzqJzDaiNs_NhhYb%2F-LDLnrub_l0hUEMXi7Uq%2F-LDMDLT0sy1TfQPGEaUR%2Fimage.png?alt=media\&token=92342a4e-c127-4890-b7e3-cc74baf4edee)

### 安装

```bash
npm install @rematch/persist
```

> 针对   @rematch/core\@0.x 使用  @rematch/persist\@0.2.1

### 设置

```javascript
import createRematchPersist from '@rematch/persist'

const persistPlugin = createRematchPersist({
  whitelist: ['modelName1'],
  throttle: 5000,
  version: 1,
})

init({
  plugins: [persistPlugin]
})
```

### Persist Gate

和React一起使用，在等待数据从 storage 中异步加载的同时显示 loading 指示器。

```javascript
import { getPersistor } from '@rematch/persist'
import { PersistGate } from 'redux-persist/es/integration/react'

const persistor = getPersistor()

const Root = () => {
  <PersistGate persistor={persistor}>
    <App />
  </PersistGate>
}
```

### 配置选项

参看  [redux-persist config docs](https://github.com/rt2zz/redux-persist/blob/master/docs/api.md#type-persistconfig)
