From 5ec797029b9c096857b692280bda59037389f587 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 30 Apr 2024 10:14:12 -0500 Subject: [PATCH] Fix `useRef` usages to be called with an explicit argument of `undefined`. (#2164) * Fix `useRef` usages to be called with an explicit `undefined` argument. - This change was made by running `npx types-react-codemod useRef-required-initial .` in preparation for React 19. * Fix type issue related to `latestSubscriptionCallbackError` --- src/components/connect.tsx | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/components/connect.tsx b/src/components/connect.tsx index bdad73719..23d4c1828 100644 --- a/src/components/connect.tsx +++ b/src/components/connect.tsx @@ -641,13 +641,17 @@ function connect< }, [didStoreComeFromProps, contextValue, subscription]) // Set up refs to coordinate values between the subscription effect and the render logic - const lastChildProps = React.useRef() + const lastChildProps = React.useRef(undefined) const lastWrapperProps = React.useRef(wrapperProps) - const childPropsFromStoreUpdate = React.useRef() + const childPropsFromStoreUpdate = React.useRef(undefined) const renderIsScheduled = React.useRef(false) const isMounted = React.useRef(false) - const latestSubscriptionCallbackError = React.useRef() + // TODO: Change this to `React.useRef(undefined)` after upgrading to React 19. + /** + * @todo Change this to `React.useRef(undefined)` after upgrading to React 19. + */ + const latestSubscriptionCallbackError = React.useRef(undefined) useIsomorphicLayoutEffect(() => { isMounted.current = true @@ -752,11 +756,11 @@ function connect< const renderedWrappedComponent = React.useMemo(() => { return ( // @ts-ignore - - ) + />) + ); }, [reactReduxForwardedRef, WrappedComponent, actualChildProps]) // If React sees the exact same element reference as last time, it bails out of re-rendering