Skip to content

Commit

Permalink
Merge pull request #4380 from aryaemami59/useRef-required-initial
Browse files Browse the repository at this point in the history
Fix `useRef` usages to be called with an explicit argument of `undefined`.
  • Loading branch information
EskiMojo14 authored May 1, 2024
2 parents 7ae805f + 30643bc commit 90937c1
Showing 1 changed file with 25 additions and 4 deletions.
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

0 comments on commit 90937c1

Please sign in to comment.