Skip to content

Commit 3d4e058

Browse files
authored
Add example for persisting api reducer
if you're using redux-persist by persisting individual reducers, you'll have multiple `REHYDRATE` actions and will need to respond to the correct one. Added a code example
1 parent e929938 commit 3d4e058

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

docs/rtk-query/usage/persistence-and-rehydration.mdx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,15 @@ export const api = createApi({
4444
baseQuery: fetchBaseQuery({ baseUrl: '/' }),
4545
// highlight-start
4646
extractRehydrationInfo(action, { reducerPath }) {
47+
// when persisting the root reducer
4748
if (action.type === REHYDRATE) {
4849
return action.payload[reducerPath]
4950
}
51+
52+
// when persisting the api reducer
53+
if (action.type === REHYDRATE && action.key === 'key used with redux-persist') {
54+
return action.payload
55+
}
5056
},
5157
// highlight-end
5258
endpoints: (build) => ({

0 commit comments

Comments
 (0)