Skip to content

Add reducerPath to extractRehydrationInfo #1645

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 25, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions packages/toolkit/src/query/createApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,12 @@ export interface CreateApiOptions<
refetchOnReconnect?: boolean

extractRehydrationInfo?: (
action: AnyAction
action: AnyAction,
{
reducerPath,
}: {
reducerPath: ReducerPath
}
) =>
| undefined
| CombinedState<
Expand Down Expand Up @@ -200,9 +205,10 @@ export function buildCreateApi<Modules extends [Module<any>, ...Module<any>[]]>(
...modules: Modules
): CreateApi<Modules[number]['name']> {
return function baseCreateApi(options) {
const extractRehydrationInfo = defaultMemoize(
options.extractRehydrationInfo ??
((() => {}) as (a: AnyAction) => undefined)
const extractRehydrationInfo = defaultMemoize((action: AnyAction) =>
options.extractRehydrationInfo?.(action, {
reducerPath: (options.reducerPath ?? 'api') as any,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could also be done with:

type ReducerPathFromCreateApiOptions<
  Options extends CreateApiOptions<any, any, any, any>
> = Options extends CreateApiOptions<any, any, infer RP, any> ? RP : unknown

reducerPath: (options.reducerPath ?? 'api') as ReducerPathFromCreateApiOptions<typeof options>,

But I don't think there is any need to do that.

Copy link
Member

@phryneas phryneas Oct 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's reaaaally not do that ^^

})
)
const optionsWithDefaults = {
reducerPath: 'api',
Expand Down