1
1
/* eslint-disable valid-jsdoc, @typescript-eslint/no-unused-vars */
2
2
import hoistStatics from 'hoist-non-react-statics'
3
3
import type { ComponentType } from 'react'
4
- import React , { useContext , useMemo , useRef } from 'react'
4
+ import * as React from 'react'
5
5
import { isValidElementType , isContextConsumer } from 'react-is'
6
6
7
7
import type { Store } from 'redux'
@@ -533,15 +533,15 @@ function connect<
533
533
props : InternalConnectProps & TOwnProps
534
534
) {
535
535
const [ propsContext , reactReduxForwardedRef , wrapperProps ] =
536
- useMemo ( ( ) => {
536
+ React . useMemo ( ( ) => {
537
537
// Distinguish between actual "data" props that were passed to the wrapper component,
538
538
// and values needed to control behavior (forwarded refs, alternate context instances).
539
539
// To maintain the wrapperProps object reference, memoize this destructuring.
540
540
const { reactReduxForwardedRef, ...wrapperProps } = props
541
541
return [ props . context , reactReduxForwardedRef , wrapperProps ]
542
542
} , [ props ] )
543
543
544
- const ContextToUse : ReactReduxContextInstance = useMemo ( ( ) => {
544
+ const ContextToUse : ReactReduxContextInstance = React . useMemo ( ( ) => {
545
545
// Users may optionally pass in a custom context instance to use instead of our ReactReduxContext.
546
546
// Memoize the check that determines which context instance we should use.
547
547
return propsContext &&
@@ -553,7 +553,7 @@ function connect<
553
553
} , [ propsContext , Context ] )
554
554
555
555
// Retrieve the store and ancestor subscription via context, if available
556
- const contextValue = useContext ( ContextToUse )
556
+ const contextValue = React . useContext ( ContextToUse )
557
557
558
558
// The store _must_ exist as either a prop or in context.
559
559
// We'll check to see if it _looks_ like a Redux store first.
@@ -587,13 +587,13 @@ function connect<
587
587
? contextValue . getServerState
588
588
: store . getState
589
589
590
- const childPropsSelector = useMemo ( ( ) => {
590
+ const childPropsSelector = React . useMemo ( ( ) => {
591
591
// The child props selector needs the store reference as an input.
592
592
// Re-create this selector whenever the store changes.
593
593
return defaultSelectorFactory ( store . dispatch , selectorFactoryOptions )
594
594
} , [ store ] )
595
595
596
- const [ subscription , notifyNestedSubs ] = useMemo ( ( ) => {
596
+ const [ subscription , notifyNestedSubs ] = React . useMemo ( ( ) => {
597
597
if ( ! shouldHandleStateChanges ) return NO_SUBSCRIPTION_ARRAY
598
598
599
599
// This Subscription's source should match where store came from: props vs. context. A component
@@ -615,7 +615,7 @@ function connect<
615
615
616
616
// Determine what {store, subscription} value should be put into nested context, if necessary,
617
617
// and memoize that value to avoid unnecessary context updates.
618
- const overriddenContextValue = useMemo ( ( ) => {
618
+ const overriddenContextValue = React . useMemo ( ( ) => {
619
619
if ( didStoreComeFromProps ) {
620
620
// This component is directly subscribed to a store from props.
621
621
// We don't want descendants reading from this store - pass down whatever
@@ -632,14 +632,14 @@ function connect<
632
632
} , [ didStoreComeFromProps , contextValue , subscription ] )
633
633
634
634
// Set up refs to coordinate values between the subscription effect and the render logic
635
- const lastChildProps = useRef < unknown > ( )
636
- const lastWrapperProps = useRef ( wrapperProps )
637
- const childPropsFromStoreUpdate = useRef < unknown > ( )
638
- const renderIsScheduled = useRef ( false )
639
- const isProcessingDispatch = useRef ( false )
640
- const isMounted = useRef ( false )
635
+ const lastChildProps = React . useRef < unknown > ( )
636
+ const lastWrapperProps = React . useRef ( wrapperProps )
637
+ const childPropsFromStoreUpdate = React . useRef < unknown > ( )
638
+ const renderIsScheduled = React . useRef ( false )
639
+ const isProcessingDispatch = React . useRef ( false )
640
+ const isMounted = React . useRef ( false )
641
641
642
- const latestSubscriptionCallbackError = useRef < Error > ( )
642
+ const latestSubscriptionCallbackError = React . useRef < Error > ( )
643
643
644
644
useIsomorphicLayoutEffect ( ( ) => {
645
645
isMounted . current = true
@@ -648,7 +648,7 @@ function connect<
648
648
}
649
649
} , [ ] )
650
650
651
- const actualChildPropsSelector = useMemo ( ( ) => {
651
+ const actualChildPropsSelector = React . useMemo ( ( ) => {
652
652
const selector = ( ) => {
653
653
// Tricky logic here:
654
654
// - This render may have been triggered by a Redux store update that produced new child props
@@ -676,7 +676,7 @@ function connect<
676
676
// about useLayoutEffect in SSR, so we try to detect environment and fall back to
677
677
// just useEffect instead to avoid the warning, since neither will run anyway.
678
678
679
- const subscribeForReact = useMemo ( ( ) => {
679
+ const subscribeForReact = React . useMemo ( ( ) => {
680
680
const subscribe = ( reactListener : ( ) => void ) => {
681
681
if ( ! subscription ) {
682
682
return ( ) => { }
@@ -741,7 +741,7 @@ function connect<
741
741
742
742
// Now that all that's done, we can finally try to actually render the child component.
743
743
// We memoize the elements for the rendered child component as an optimization.
744
- const renderedWrappedComponent = useMemo ( ( ) => {
744
+ const renderedWrappedComponent = React . useMemo ( ( ) => {
745
745
return (
746
746
// @ts -ignore
747
747
< WrappedComponent
@@ -753,7 +753,7 @@ function connect<
753
753
754
754
// If React sees the exact same element reference as last time, it bails out of re-rendering
755
755
// that child, same as if it was wrapped in React.memo() or returned false from shouldComponentUpdate.
756
- const renderedChild = useMemo ( ( ) => {
756
+ const renderedChild = React . useMemo ( ( ) => {
757
757
if ( shouldHandleStateChanges ) {
758
758
// If this component is subscribed to store updates, we need to pass its own
759
759
// subscription instance down to our descendants. That means rendering the same
0 commit comments