Skip to content
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

Fix useRef usages to be called with an explicit argument of undefined. #4380

Merged
merged 2 commits into from
May 1, 2024
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
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