Skip to content

Commit 693ecfd

Browse files
committed
fix docs again
1 parent d0f73d5 commit 693ecfd

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,21 @@ box with the `autoMergeLevel1` or `autoMergeLevel2` [state reconcilers](https://
3737
when persisting the root reducer, or with the `autoMergeLevel1` reconciler when persisting just the api reducer.
3838

3939
```ts title="redux-persist rehydration example"
40+
import type { Action, PayloadAction } from '@reduxjs/toolkit'
4041
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'
4142
import { REHYDRATE } from 'redux-persist'
4243

44+
type RootState = any // normally inferred from state
45+
46+
function isHydrateAction(action: Action): action is PayloadAction<RootState> {
47+
return action.type === REHYDRATE
48+
}
49+
4350
export const api = createApi({
4451
baseQuery: fetchBaseQuery({ baseUrl: '/' }),
4552
// highlight-start
4653
extractRehydrationInfo(action, { reducerPath }) {
47-
if (action.type === REHYDRATE) {
54+
if (isHydrateAction(action)) {
4855
return action.payload[reducerPath]
4956
}
5057
},

packages/toolkit/src/createSlice.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,15 +186,15 @@ export interface CreateSliceOptions<
186186
*
187187
* @example
188188
```ts
189-
import { createAction, createSlice, Action, UnknownAction } from '@reduxjs/toolkit'
189+
import { createAction, createSlice, Action } from '@reduxjs/toolkit'
190190
const incrementBy = createAction<number>('incrementBy')
191191
const decrement = createAction('decrement')
192192
193193
interface RejectedAction extends Action {
194194
error: Error
195195
}
196196
197-
function isRejectedAction(action: UnknownAction): action is RejectedAction {
197+
function isRejectedAction(action: Action): action is RejectedAction {
198198
return action.type.endsWith('rejected')
199199
}
200200
@@ -240,8 +240,10 @@ interface ReducerDefinition<T extends ReducerType = ReducerType> {
240240
[reducerDefinitionType]: T
241241
}
242242

243-
export interface CaseReducerDefinition<S = any, A extends Action = UnknownAction>
244-
extends CaseReducer<S, A>,
243+
export interface CaseReducerDefinition<
244+
S = any,
245+
A extends Action = UnknownAction
246+
> extends CaseReducer<S, A>,
245247
ReducerDefinition<ReducerType.reducer> {}
246248

247249
/**

packages/toolkit/src/query/createApi.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,14 +159,21 @@ export interface CreateApiOptions<
159159
*
160160
* ```ts
161161
* // codeblock-meta title="next-redux-wrapper rehydration example"
162+
* import type { Action, PayloadAction } from '@reduxjs/toolkit'
162163
* import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'
163164
* import { HYDRATE } from 'next-redux-wrapper'
164165
*
166+
* type RootState = any; // normally inferred from state
167+
*
168+
* function isHydrateAction(action: Action): action is PayloadAction<RootState> {
169+
* return action.type === HYDRATE
170+
* }
171+
*
165172
* export const api = createApi({
166173
* baseQuery: fetchBaseQuery({ baseUrl: '/' }),
167174
* // highlight-start
168175
* extractRehydrationInfo(action, { reducerPath }) {
169-
* if (action.type === HYDRATE) {
176+
* if (isHydrateAction(action)) {
170177
* return action.payload[reducerPath]
171178
* }
172179
* },

0 commit comments

Comments
 (0)