Skip to content

Commit 5ec7970

Browse files
authored
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`
1 parent d44ff74 commit 5ec7970

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

Diff for: src/components/connect.tsx

+10-6
Original file line numberDiff line numberDiff line change
@@ -641,13 +641,17 @@ function connect<
641641
}, [didStoreComeFromProps, contextValue, subscription])
642642

643643
// Set up refs to coordinate values between the subscription effect and the render logic
644-
const lastChildProps = React.useRef<unknown>()
644+
const lastChildProps = React.useRef<unknown>(undefined)
645645
const lastWrapperProps = React.useRef(wrapperProps)
646-
const childPropsFromStoreUpdate = React.useRef<unknown>()
646+
const childPropsFromStoreUpdate = React.useRef<unknown>(undefined)
647647
const renderIsScheduled = React.useRef(false)
648648
const isMounted = React.useRef(false)
649649

650-
const latestSubscriptionCallbackError = React.useRef<Error>()
650+
// TODO: Change this to `React.useRef<Error>(undefined)` after upgrading to React 19.
651+
/**
652+
* @todo Change this to `React.useRef<Error>(undefined)` after upgrading to React 19.
653+
*/
654+
const latestSubscriptionCallbackError = React.useRef<Error | undefined>(undefined)
651655

652656
useIsomorphicLayoutEffect(() => {
653657
isMounted.current = true
@@ -752,11 +756,11 @@ function connect<
752756
const renderedWrappedComponent = React.useMemo(() => {
753757
return (
754758
// @ts-ignore
755-
<WrappedComponent
759+
(<WrappedComponent
756760
{...actualChildProps}
757761
ref={reactReduxForwardedRef}
758-
/>
759-
)
762+
/>)
763+
);
760764
}, [reactReduxForwardedRef, WrappedComponent, actualChildProps])
761765

762766
// If React sees the exact same element reference as last time, it bails out of re-rendering

0 commit comments

Comments
 (0)