Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: reduxjs/redux-toolkit
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.9.6
Choose a base ref
...
head repository: reduxjs/redux-toolkit
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v1.9.7
Choose a head ref
  • 17 commits
  • 8 files changed
  • 6 contributors

Commits on Sep 27, 2023

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    0d05480 View commit details

Commits on Sep 28, 2023

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    52ab548 View commit details

Commits on Oct 2, 2023

  1. Update usage-without-react-hooks.mdx

    Add examples of what you can do with the subscription in the first subscribe code example
    Azeirah authored Oct 2, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    b3d66a0 View commit details
  2. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    0faafdb View commit details
  3. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    c5067bf View commit details
  4. Rework named hooks type (v1.9)

    ben.durrant committed Oct 2, 2023
    Copy the full SHA
    eb55056 View commit details
  5. split types

    ben.durrant committed Oct 2, 2023
    Copy the full SHA
    928279b View commit details

Commits on Oct 3, 2023

  1. Copy the full SHA
    79b4009 View commit details
  2. Copy the full SHA
    55bb510 View commit details
  3. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    ad8d983 View commit details
  4. Copy the full SHA
    6234e63 View commit details

Commits on Oct 4, 2023

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    ed7ce5e View commit details
  2. Add phryneas/ts-version

    markerikson authored and julian-ford committed Oct 4, 2023
    Copy the full SHA
    cab1807 View commit details
  3. Copy the full SHA
    59b2de7 View commit details
  4. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    49e00b4 View commit details
  5. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    aaf615a View commit details
  6. Release 1.9.7

    markerikson committed Oct 4, 2023
    Copy the full SHA
    2fe9e73 View commit details
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -105,7 +105,7 @@ jobs:
fail-fast: false
matrix:
node: ['16.x']
ts: ['4.1', '4.2', '4.3', '4.4', '4.5', '4.6', '4.7', '4.8', '4.9.2-rc']
ts: ['4.1', '4.2', '4.3', '4.4', '4.5', '4.6', '4.7', '4.8', '4.9.5', '5.0', '5.1', '5.2']
steps:
- name: Checkout repo
uses: actions/checkout@v2
2 changes: 1 addition & 1 deletion docs/introduction/getting-started.md
Original file line number Diff line number Diff line change
@@ -120,7 +120,7 @@ import { createApi } from '@reduxjs/toolkit/query/react'

RTK Query includes these APIs:

- [`createApi()`](../rtk-query/api/createApi.mdx): The core of RTK Query's functionality. It allows you to define a set of endpoints describe how to retrieve data from a series of endpoints, including configuration of how to fetch and transform that data. In most cases, you should use this once per app, with "one API slice per base URL" as a rule of thumb.
- [`createApi()`](../rtk-query/api/createApi.mdx): The core of RTK Query's functionality. It allows you to define a set of endpoints and describe how to retrieve data from a series of endpoints, including configuration of how to fetch and transform that data. In most cases, you should use this once per app, with "one API slice per base URL" as a rule of thumb.
- [`fetchBaseQuery()`](../rtk-query/api/fetchBaseQuery.mdx): A small wrapper around [`fetch`](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) that aims to simplify requests. Intended as the recommended `baseQuery` to be used in `createApi` for the majority of users.
- [`<ApiProvider />`](../rtk-query/api/ApiProvider.mdx): Can be used as a `Provider` if you **do not already have a Redux store**.
- [`setupListeners()`](../rtk-query/api/setupListeners.mdx): A utility used to enable `refetchOnMount` and `refetchOnReconnect` behaviors.
7 changes: 4 additions & 3 deletions docs/rtk-query/usage/customizing-queries.mdx
Original file line number Diff line number Diff line change
@@ -369,16 +369,17 @@ const axiosBaseQuery =
method: AxiosRequestConfig['method']
data?: AxiosRequestConfig['data']
params?: AxiosRequestConfig['params']
headers?: AxiosRequestConfig['headers']
},
unknown,
unknown
> =>
async ({ url, method, data, params }) => {
async ({ url, method, data, params, headers }) => {
try {
const result = await axios({ url: baseUrl + url, method, data, params })
const result = await axios({ url: baseUrl + url, method, data, params, headers })
return { data: result.data }
} catch (axiosError) {
let err = axiosError as AxiosError
const err = axiosError as AxiosError
return {
error: {
status: err.response?.status,
3 changes: 2 additions & 1 deletion docs/rtk-query/usage/usage-without-react-hooks.mdx
Original file line number Diff line number Diff line change
@@ -23,7 +23,8 @@ Cache subscriptions are used to tell RTK Query that it needs to fetch data for a
With React hooks, this behavior is instead handled within [`useQuery`](../api/created-api/hooks.mdx#usequery), [`useQuerySubscription`](../api/created-api/hooks.mdx#usequerysubscription), [`useLazyQuery`](../api/created-api/hooks.mdx#uselazyquery), and [`useLazyQuerySubscription`](../api/created-api/hooks.mdx#uselazyquerysubscription).

```ts title="Subscribing to cached data" no-transpile
dispatch(api.endpoints.getPosts.initiate())
// interact with the cache in the same way as you would with a useFetch...() hook
const {data, refetch, isLoading, isSuccess, /*...*/} = dispatch(api.endpoints.getPosts.initiate())
```

## Removing a subscription
3 changes: 2 additions & 1 deletion packages/toolkit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@reduxjs/toolkit",
"version": "1.9.6",
"version": "1.9.7",
"description": "The official, opinionated, batteries-included toolset for efficient Redux development",
"author": "Mark Erikson <mark@isquaredsoftware.com>",
"license": "MIT",
@@ -28,6 +28,7 @@
"types": "dist/index.d.ts",
"devDependencies": {
"@microsoft/api-extractor": "^7.13.2",
"@phryneas/ts-version": "^1.0.2",
"@size-limit/preset-small-lib": "^4.11.0",
"@testing-library/react": "^13.3.0",
"@testing-library/user-event": "^13.1.5",
55 changes: 33 additions & 22 deletions packages/toolkit/src/query/react/namedHooks.ts
Original file line number Diff line number Diff line change
@@ -6,26 +6,37 @@ import type {
QueryDefinition,
} from '@reduxjs/toolkit/query'

type QueryHookNames<Definitions extends EndpointDefinitions> = {
[K in keyof Definitions as Definitions[K] extends {
type: DefinitionType.query
}
? `use${Capitalize<K & string>}Query`
: never]: UseQuery<
Extract<Definitions[K], QueryDefinition<any, any, any, any>>
>
}

type LazyQueryHookNames<Definitions extends EndpointDefinitions> = {
[K in keyof Definitions as Definitions[K] extends {
type: DefinitionType.query
}
? `useLazy${Capitalize<K & string>}Query`
: never]: UseLazyQuery<
Extract<Definitions[K], QueryDefinition<any, any, any, any>>
>
}

type MutationHookNames<Definitions extends EndpointDefinitions> = {
[K in keyof Definitions as Definitions[K] extends {
type: DefinitionType.mutation
}
? `use${Capitalize<K & string>}Mutation`
: never]: UseMutation<
Extract<Definitions[K], MutationDefinition<any, any, any, any>>
>
}

export type HooksWithUniqueNames<Definitions extends EndpointDefinitions> =
keyof Definitions extends infer Keys
? Keys extends string
? Definitions[Keys] extends { type: DefinitionType.query }
? {
[K in Keys as `use${Capitalize<K>}Query`]: UseQuery<
Extract<Definitions[K], QueryDefinition<any, any, any, any>>
>
} &
{
[K in Keys as `useLazy${Capitalize<K>}Query`]: UseLazyQuery<
Extract<Definitions[K], QueryDefinition<any, any, any, any>>
>
}
: Definitions[Keys] extends { type: DefinitionType.mutation }
? {
[K in Keys as `use${Capitalize<K>}Mutation`]: UseMutation<
Extract<Definitions[K], MutationDefinition<any, any, any, any>>
>
}
: never
: never
: never
QueryHookNames<Definitions> &
LazyQueryHookNames<Definitions> &
MutationHookNames<Definitions>
19 changes: 17 additions & 2 deletions packages/toolkit/src/tests/createAsyncThunk.typetest.ts
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@ import type {
AsyncThunkFulfilledActionCreator,
AsyncThunkRejectedActionCreator,
} from '@internal/createAsyncThunk'
import type { TSVersion } from '@phryneas/ts-version'

const ANY = {} as any
const defaultDispatch = (() => {}) as ThunkDispatch<{}, any, AnyAction>
@@ -287,8 +288,22 @@ const anyAction = { type: 'foo' } as AnyAction
// in that case, we have to forbid this behaviour or it will make arguments optional everywhere
{
const asyncThunk = createAsyncThunk('test', (arg?: number) => 0)
expectType<(arg?: number) => any>(asyncThunk)
asyncThunk()

// Per https://github.com/reduxjs/redux-toolkit/issues/3758#issuecomment-1742152774 , this is a bug in
// TS 5.1 and 5.2, that is fixed in 5.3. Conditionally run the TS assertion here.
type IsTS51Or52 = TSVersion.Major extends 5
? TSVersion.Minor extends 1 | 2
? true
: false
: false

type expectedType = IsTS51Or52 extends true
? (arg: number) => any
: (arg?: number) => any
expectType<expectedType>(asyncThunk)
// We _should_ be able to call this with no arguments, but we run into that error in 5.1 and 5.2.
// Disabling this for now.
// asyncThunk()
asyncThunk(5)
// @ts-expect-error
asyncThunk('string')
8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
@@ -6421,6 +6421,13 @@ __metadata:
languageName: node
linkType: hard

"@phryneas/ts-version@npm:^1.0.2":
version: 1.0.2
resolution: "@phryneas/ts-version@npm:1.0.2"
checksum: d51914a8ea35ff8b686a9379b9e9fe6d5b5feaf2e7511b880d2835015736e33bc82952bbc369918f251d4a755f32f4a9c4a34b0ec4dfdbc3e87a41d26401105c
languageName: node
linkType: hard

"@pmmmwh/react-refresh-webpack-plugin@npm:^0.5.3":
version: 0.5.7
resolution: "@pmmmwh/react-refresh-webpack-plugin@npm:0.5.7"
@@ -6554,6 +6561,7 @@ __metadata:
resolution: "@reduxjs/toolkit@workspace:packages/toolkit"
dependencies:
"@microsoft/api-extractor": ^7.13.2
"@phryneas/ts-version": ^1.0.2
"@size-limit/preset-small-lib": ^4.11.0
"@testing-library/react": ^13.3.0
"@testing-library/user-event": ^13.1.5