Skip to content

Commit 4b8d93d

Browse files
grumpyTofuAustin Felix
andauthored
Updated redux-persist guidance (#1265)
Co-authored-by: Austin Felix <[email protected]>
1 parent 8fec378 commit 4b8d93d

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

docs/usage/usage-guide.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,6 +1101,30 @@ ReactDOM.render(
11011101
)
11021102
```
11031103

1104+
Additionally, you can purge any persisted state by adding an extra reducer to the specific slice that you would like to clear when calling persistor.purge(). This is especially helpful when you are looking to clear persisted state on a dispatched logout action.
1105+
1106+
```ts
1107+
import { PURGE } from "redux-persist";
1108+
1109+
...
1110+
extraReducers: (builder) => {
1111+
builder.addCase(PURGE, (state) => {
1112+
customEntityAdapter.removeAll(state);
1113+
});
1114+
}
1115+
```
1116+
1117+
It is also strongly recommended to blacklist any api(s) that you have configured with RTK Query. If the api slice reducer is not blacklisted, the api cache will be automatically persisted and restored which could leave you with phantom subscriptions from components that do not exist any more. Configuring this should look something like this:
1118+
1119+
```ts
1120+
const persistConfig = {
1121+
key: "root",
1122+
version: 1,
1123+
storage,
1124+
blacklist: [pokemonApi.reducerPath],
1125+
};
1126+
```
1127+
11041128
See [Redux Toolkit #121: How to use this with Redux-Persist?](https://github.com/reduxjs/redux-toolkit/issues/121) and [Redux-Persist #988: non-serializable value error](https://github.com/rt2zz/redux-persist/issues/988#issuecomment-552242978) for further discussion.
11051129

11061130
### Use with React-Redux-Firebase

0 commit comments

Comments
 (0)