Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/components/connect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -747,11 +747,14 @@ function connect<
// Now that all that's done, we can finally try to actually render the child component.
// We memoize the elements for the rendered child component as an optimization.
const renderedWrappedComponent = React.useMemo(() => {
const effectiveProps = {...actualChildProps};
if (forwardRef) {
effectiveProps.ref = reactReduxForwardedRef
}
return (
// @ts-ignore
<WrappedComponent
{...actualChildProps}
ref={reactReduxForwardedRef}
{...effectiveProps}
/>
)
}, [reactReduxForwardedRef, WrappedComponent, actualChildProps])
Expand Down
26 changes: 26 additions & 0 deletions test/components/connect.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2588,6 +2588,32 @@ describe('React', () => {

expect(tester.getByTestId('a')).toHaveTextContent('42')
})

it('should not override ref property when not asked to.', async () => {
type RootStateType = {}
const store = createStore(() => ({}))
type RefReceiverPropsType = {}
const RefReceiver = React.forwardRef<HTMLSpanElement, RefReceiverPropsType>(
(props: RefReceiverPropsType, ref) => <span ref={ref} />
);
type RefReceiverNoDispatchType = null
const decorator = connect<
RefReceiverPropsType,
RefReceiverNoDispatchType,
RefReceiverPropsType,
RootStateType
>(null, null, null, {
forwardRef: IS_REACT_18
})
const DecoratedRefReceiver = decorator(RefReceiver)
const testRef = React.createRef<HTMLSpanElement>()
rtl.render(
<ProviderMock store={store}>
<DecoratedRefReceiver ref={testRef} />
</ProviderMock>
)
expect(testRef.current).toBeInstanceOf(HTMLSpanElement);
})
})

describe('Factory functions for mapState/mapDispatch', () => {
Expand Down
Loading