Skip to content

Commit

Permalink
Cleanup more code after pure removal
Browse files Browse the repository at this point in the history
  • Loading branch information
Andarist committed Dec 23, 2021
1 parent 93d5ee5 commit 45e5709
Showing 1 changed file with 1 addition and 8 deletions.
9 changes: 1 addition & 8 deletions src/components/connect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,6 @@ function connect<
const displayName = `Connect(${wrappedComponentName})`

const selectorFactoryOptions: SelectorFactoryOptions<any, any, any, any> = {
pure,
shouldHandleStateChanges,
displayName,
wrappedComponentName,
Expand All @@ -543,11 +542,6 @@ function connect<
areMergedPropsEqual,
}

// If we aren't running in "pure" mode, we don't want to memoize values.
// To avoid conditionally calling hooks, we fall back to a tiny wrapper
// that just executes the given callback immediately.
const usePureOnlyMemo = pure ? useMemo : (callback: () => any) => callback()

function ConnectFunction<TOwnProps>(
props: InternalConnectProps & TOwnProps
) {
Expand Down Expand Up @@ -667,7 +661,7 @@ function connect<
}
}, [])

const actualChildPropsSelector = usePureOnlyMemo(() => {
const actualChildPropsSelector = useMemo(() => {
const selector = () => {
// Tricky logic here:
// - This render may have been triggered by a Redux store update that produced new child props
Expand Down Expand Up @@ -790,7 +784,6 @@ function connect<
return renderedChild
}

// If we're in "pure" mode, ensure our wrapper component only re-renders when incoming props have changed.
const _Connect = React.memo(ConnectFunction)

type ConnectedWrapperComponent = typeof _Connect & {
Expand Down

0 comments on commit 45e5709

Please sign in to comment.