Skip to content

Commit 63bde33

Browse files
authored
Rename internal forwardedRef usage (reduxjs#1553)
* Rename internal forwardedRef usage to reactReduxForwardedRef to limit namespace collision of a parent component passing in a prop called forwardedRef * Formatting changes Co-authored-by: Drew Schuster <[email protected]>
1 parent d66d9f5 commit 63bde33

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

Diff for: src/components/connectAdvanced.js

+15-6
Original file line numberDiff line numberDiff line change
@@ -272,12 +272,16 @@ export default function connectAdvanced(
272272
const usePureOnlyMemo = pure ? useMemo : callback => callback()
273273

274274
function ConnectFunction(props) {
275-
const [propsContext, forwardedRef, wrapperProps] = useMemo(() => {
275+
const [
276+
propsContext,
277+
reactReduxForwardedRef,
278+
wrapperProps
279+
] = useMemo(() => {
276280
// Distinguish between actual "data" props that were passed to the wrapper component,
277281
// and values needed to control behavior (forwarded refs, alternate context instances).
278282
// To maintain the wrapperProps object reference, memoize this destructuring.
279-
const { forwardedRef, ...wrapperProps } = props
280-
return [props.context, forwardedRef, wrapperProps]
283+
const { reactReduxForwardedRef, ...wrapperProps } = props
284+
return [props.context, reactReduxForwardedRef, wrapperProps]
281285
}, [props])
282286

283287
const ContextToUse = useMemo(() => {
@@ -437,8 +441,13 @@ export default function connectAdvanced(
437441
// Now that all that's done, we can finally try to actually render the child component.
438442
// We memoize the elements for the rendered child component as an optimization.
439443
const renderedWrappedComponent = useMemo(
440-
() => <WrappedComponent {...actualChildProps} ref={forwardedRef} />,
441-
[forwardedRef, WrappedComponent, actualChildProps]
444+
() => (
445+
<WrappedComponent
446+
{...actualChildProps}
447+
ref={reactReduxForwardedRef}
448+
/>
449+
),
450+
[reactReduxForwardedRef, WrappedComponent, actualChildProps]
442451
)
443452

444453
// If React sees the exact same element reference as last time, it bails out of re-rendering
@@ -472,7 +481,7 @@ export default function connectAdvanced(
472481
props,
473482
ref
474483
) {
475-
return <Connect {...props} forwardedRef={ref} />
484+
return <Connect {...props} reactReduxForwardedRef={ref} />
476485
})
477486

478487
forwarded.displayName = displayName

0 commit comments

Comments
 (0)