Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/reduxjs/redux-toolkit int…
Browse files Browse the repository at this point in the history
…o cut-down-on-resolutions
  • Loading branch information
aryaemami59 committed May 1, 2024
2 parents 9a82433 + d955fb2 commit def0ce1
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 17 deletions.
9 changes: 4 additions & 5 deletions docs/rtk-query/usage-with-typescript.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ When using `fetchBaseQuery`, the `error` property returned from a hook will have
If an error is present, you can access error properties after narrowing the type to either `FetchBaseQueryError` or `SerializedError`.

```tsx no-transpile
import { api } from './services/api'
import { usePostsQuery } from './services/api'

function PostDetail() {
const { data, error, isLoading } = usePostsQuery()
Expand All @@ -613,10 +613,9 @@ function PostDetail() {
<div>{errMsg}</div>
</div>
)
} else {
// you can access all properties of `SerializedError` here
return <div>{error.message}</div>
}
}
// you can access all properties of `SerializedError` here
return <div>{error.message}</div>
}

if (data) {
Expand Down
3 changes: 2 additions & 1 deletion examples/query/react/basic/src/test/test-utils.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { render } from '@testing-library/react'
import type { RenderOptions } from '@testing-library/react'
import React, { PropsWithChildren } from 'react'
import type React from 'react'
import type { PropsWithChildren, JSX } from 'react'
import { Provider } from 'react-redux'
import { setupStore } from '../store'
import type { AppStore, RootState } from '../store'
Expand Down
29 changes: 25 additions & 4 deletions packages/toolkit/src/query/react/buildHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,15 @@ export function buildHooks<Definitions extends EndpointDefinitions>({
Definitions
>
const dispatch = useDispatch<ThunkDispatch<any, any, UnknownAction>>()
const subscriptionSelectorsRef = useRef<SubscriptionSelectors>()

// TODO: Change this to `useRef<SubscriptionSelectors>(undefined)` after upgrading to React 19.
/**
* @todo Change this to `useRef<SubscriptionSelectors>(undefined)` after upgrading to React 19.
*/
const subscriptionSelectorsRef = useRef<
SubscriptionSelectors | undefined
>(undefined)

if (!subscriptionSelectorsRef.current) {
const returnedValue = dispatch(
api.internalActions.internal_getRTKQSubscriptions(),
Expand Down Expand Up @@ -781,7 +789,13 @@ export function buildHooks<Definitions extends EndpointDefinitions>({

const lastRenderHadSubscription = useRef(false)

const promiseRef = useRef<QueryActionCreatorResult<any>>()
// TODO: Change this to `useRef<QueryActionCreatorResult<any>>(undefined)` after upgrading to React 19.
/**
* @todo Change this to `useRef<QueryActionCreatorResult<any>>(undefined)` after upgrading to React 19.
*/
const promiseRef = useRef<QueryActionCreatorResult<any> | undefined>(
undefined,
)

let { queryCacheKey, requestId } = promiseRef.current || {}

Expand Down Expand Up @@ -886,7 +900,14 @@ export function buildHooks<Definitions extends EndpointDefinitions>({
const dispatch = useDispatch<ThunkDispatch<any, any, UnknownAction>>()

const [arg, setArg] = useState<any>(UNINITIALIZED_VALUE)
const promiseRef = useRef<QueryActionCreatorResult<any> | undefined>()

// TODO: Change this to `useRef<QueryActionCreatorResult<any>>(undefined)` after upgrading to React 19.
/**
* @todo Change this to `useRef<QueryActionCreatorResult<any>>(undefined)` after upgrading to React 19.
*/
const promiseRef = useRef<QueryActionCreatorResult<any> | undefined>(
undefined,
)

const stableSubscriptionOptions = useShallowStableValue({
refetchOnReconnect,
Expand Down Expand Up @@ -966,7 +987,7 @@ export function buildHooks<Definitions extends EndpointDefinitions>({

type ApiRootState = Parameters<ReturnType<typeof select>>[0]

const lastValue = useRef<any>()
const lastValue = useRef<any>(undefined)

const selectDefaultResult: Selector<ApiRootState, any, [any]> = useMemo(
() =>
Expand Down
2 changes: 1 addition & 1 deletion website/src/theme/DocPage/Layout/Main/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ComponentProps } from 'react'
import type { ComponentProps, JSX } from 'react'
import React from 'react'
import Main from '@theme-original/DocPage/Layout/Main'
import type MainType from '@theme-original/DocPage/Layout/Main'
Expand Down
12 changes: 6 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9007,12 +9007,12 @@ __metadata:
linkType: hard

"@types/react@npm:*, @types/react@npm:^18.0, @types/react@npm:^18.0.12, @types/react@npm:^18.0.5, @types/react@npm:^18.2.77":
version: 18.2.77
resolution: "@types/react@npm:18.2.77"
version: 18.3.1
resolution: "@types/react@npm:18.3.1"
dependencies:
"@types/prop-types": "npm:*"
csstype: "npm:^3.0.2"
checksum: 10/80d7ad9cf13e15895a857c66f5b0c1ce758c1e7580a76936d8d1b19c71e4485fa4b35d762a1de98de4eb91506cbc8507582c9a979f357b6f5f75f86009d8ca07
checksum: 10/baa6b8a75c471c89ebf3477b4feab57102ced25f0c1e553dd04ef6a1f0def28d5e0172fa626a631f22e223f840b5aaa2403b2d4bb671c83c5a9d6c7ae39c7a05
languageName: node
linkType: hard

Expand Down Expand Up @@ -24655,11 +24655,11 @@ __metadata:
linkType: hard

"react@npm:^18.1.0, react@npm:^18.2.0":
version: 18.2.0
resolution: "react@npm:18.2.0"
version: 18.3.1
resolution: "react@npm:18.3.1"
dependencies:
loose-envify: "npm:^1.1.0"
checksum: 10/b9214a9bd79e99d08de55f8bef2b7fc8c39630be97c4e29d7be173d14a9a10670b5325e94485f74cd8bff4966ef3c78ee53c79a7b0b9b70cba20aa8973acc694
checksum: 10/261137d3f3993eaa2368a83110466fc0e558bc2c7f7ae7ca52d94f03aac945f45146bd85e5f481044db1758a1dbb57879e2fcdd33924e2dde1bdc550ce73f7bf
languageName: node
linkType: hard

Expand Down

0 comments on commit def0ce1

Please sign in to comment.