Skip to content

Commit

Permalink
Fix useRef usages to be called with an explicit argument of `undefi…
Browse files Browse the repository at this point in the history
…ned`. (#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`
  • Loading branch information
aryaemami59 committed Apr 30, 2024
1 parent d44ff74 commit 5ec7970
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/components/connect.tsx
Expand Up @@ -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<unknown>()
const lastChildProps = React.useRef<unknown>(undefined)
const lastWrapperProps = React.useRef(wrapperProps)
const childPropsFromStoreUpdate = React.useRef<unknown>()
const childPropsFromStoreUpdate = React.useRef<unknown>(undefined)
const renderIsScheduled = React.useRef(false)
const isMounted = React.useRef(false)

const latestSubscriptionCallbackError = React.useRef<Error>()
// TODO: Change this to `React.useRef<Error>(undefined)` after upgrading to React 19.
/**
* @todo Change this to `React.useRef<Error>(undefined)` after upgrading to React 19.
*/
const latestSubscriptionCallbackError = React.useRef<Error | undefined>(undefined)

useIsomorphicLayoutEffect(() => {
isMounted.current = true
Expand Down Expand Up @@ -752,11 +756,11 @@ function connect<
const renderedWrappedComponent = React.useMemo(() => {
return (
// @ts-ignore
<WrappedComponent
(<WrappedComponent
{...actualChildProps}
ref={reactReduxForwardedRef}
/>
)
/>)
);
}, [reactReduxForwardedRef, WrappedComponent, actualChildProps])

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

0 comments on commit 5ec7970

Please sign in to comment.