diff --git a/packages/toolkit/src/query/react/buildHooks.ts b/packages/toolkit/src/query/react/buildHooks.ts index d2432acc93..9ce5671a31 100644 --- a/packages/toolkit/src/query/react/buildHooks.ts +++ b/packages/toolkit/src/query/react/buildHooks.ts @@ -740,7 +740,15 @@ export function buildHooks({ Definitions > const dispatch = useDispatch>() - const subscriptionSelectorsRef = useRef() + + // TODO: Change this to `useRef(undefined)` after upgrading to React 19. + /** + * @todo Change this to `useRef(undefined)` after upgrading to React 19. + */ + const subscriptionSelectorsRef = useRef< + SubscriptionSelectors | undefined + >(undefined) + if (!subscriptionSelectorsRef.current) { const returnedValue = dispatch( api.internalActions.internal_getRTKQSubscriptions(), @@ -781,7 +789,13 @@ export function buildHooks({ const lastRenderHadSubscription = useRef(false) - const promiseRef = useRef>() + // TODO: Change this to `useRef>(undefined)` after upgrading to React 19. + /** + * @todo Change this to `useRef>(undefined)` after upgrading to React 19. + */ + const promiseRef = useRef | undefined>( + undefined, + ) let { queryCacheKey, requestId } = promiseRef.current || {} @@ -886,7 +900,14 @@ export function buildHooks({ const dispatch = useDispatch>() const [arg, setArg] = useState(UNINITIALIZED_VALUE) - const promiseRef = useRef | undefined>() + + // TODO: Change this to `useRef>(undefined)` after upgrading to React 19. + /** + * @todo Change this to `useRef>(undefined)` after upgrading to React 19. + */ + const promiseRef = useRef | undefined>( + undefined, + ) const stableSubscriptionOptions = useShallowStableValue({ refetchOnReconnect, @@ -966,7 +987,7 @@ export function buildHooks({ type ApiRootState = Parameters>[0] - const lastValue = useRef() + const lastValue = useRef(undefined) const selectDefaultResult: Selector = useMemo( () =>