Skip to content

Commit

Permalink
fix docs again
Browse files Browse the repository at this point in the history
  • Loading branch information
EskiMojo14 committed May 30, 2023
1 parent d0f73d5 commit 693ecfd
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
9 changes: 8 additions & 1 deletion docs/rtk-query/usage/persistence-and-rehydration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,21 @@ box with the `autoMergeLevel1` or `autoMergeLevel2` [state reconcilers](https://
when persisting the root reducer, or with the `autoMergeLevel1` reconciler when persisting just the api reducer.

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

type RootState = any // normally inferred from state

function isHydrateAction(action: Action): action is PayloadAction<RootState> {
return action.type === REHYDRATE
}

export const api = createApi({
baseQuery: fetchBaseQuery({ baseUrl: '/' }),
// highlight-start
extractRehydrationInfo(action, { reducerPath }) {
if (action.type === REHYDRATE) {
if (isHydrateAction(action)) {
return action.payload[reducerPath]
}
},
Expand Down
10 changes: 6 additions & 4 deletions packages/toolkit/src/createSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,15 @@ export interface CreateSliceOptions<
*
* @example
```ts
import { createAction, createSlice, Action, UnknownAction } from '@reduxjs/toolkit'
import { createAction, createSlice, Action } from '@reduxjs/toolkit'
const incrementBy = createAction<number>('incrementBy')
const decrement = createAction('decrement')
interface RejectedAction extends Action {
error: Error
}
function isRejectedAction(action: UnknownAction): action is RejectedAction {
function isRejectedAction(action: Action): action is RejectedAction {
return action.type.endsWith('rejected')
}
Expand Down Expand Up @@ -240,8 +240,10 @@ interface ReducerDefinition<T extends ReducerType = ReducerType> {
[reducerDefinitionType]: T
}

export interface CaseReducerDefinition<S = any, A extends Action = UnknownAction>
extends CaseReducer<S, A>,
export interface CaseReducerDefinition<
S = any,
A extends Action = UnknownAction
> extends CaseReducer<S, A>,
ReducerDefinition<ReducerType.reducer> {}

/**
Expand Down
9 changes: 8 additions & 1 deletion packages/toolkit/src/query/createApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,21 @@ export interface CreateApiOptions<
*
* ```ts
* // codeblock-meta title="next-redux-wrapper rehydration example"
* import type { Action, PayloadAction } from '@reduxjs/toolkit'
* import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'
* import { HYDRATE } from 'next-redux-wrapper'
*
* type RootState = any; // normally inferred from state
*
* function isHydrateAction(action: Action): action is PayloadAction<RootState> {
* return action.type === HYDRATE
* }
*
* export const api = createApi({
* baseQuery: fetchBaseQuery({ baseUrl: '/' }),
* // highlight-start
* extractRehydrationInfo(action, { reducerPath }) {
* if (action.type === HYDRATE) {
* if (isHydrateAction(action)) {
* return action.payload[reducerPath]
* }
* },
Expand Down

0 comments on commit 693ecfd

Please sign in to comment.