|
1 | 1 | /* eslint-disable import/no-unresolved, import/extensions */
|
2 |
| -import React from 'react'; |
| 2 | +import React, { forwardRef } from 'react'; |
3 | 3 | import { connect } from 'react-redux';
|
4 | 4 | import hoistStatics from 'hoist-non-react-statics';
|
5 | 5 | /* eslint-enable import/no-unresolved, import/extensions */
|
@@ -39,7 +39,11 @@ const easyConnect = injectProps => (
|
39 | 39 | }
|
40 | 40 | : mapDispatchToProps;
|
41 | 41 |
|
42 |
| - return connect(mapStateToProps, modifiedMapDispatchToProps, ...otherArgs); |
| 42 | + return connect( |
| 43 | + mapStateToProps, |
| 44 | + modifiedMapDispatchToProps, |
| 45 | + ...otherArgs, |
| 46 | + ); |
43 | 47 | };
|
44 | 48 |
|
45 | 49 | export default (...args) => (WrappedComponent) => {
|
@@ -73,30 +77,34 @@ export default (...args) => (WrappedComponent) => {
|
73 | 77 | );
|
74 | 78 | };
|
75 | 79 |
|
76 |
| - getWrappedInstance = () => |
77 |
| - this.innerRef && this.innerRef.getWrappedInstance |
78 |
| - ? this.innerRef.getWrappedInstance() |
79 |
| - : null; |
80 |
| - |
81 | 80 | render() {
|
82 | 81 | const { ConnectedComponent } = this;
|
| 82 | + // eslint-disable-next-line react/prop-types |
| 83 | + const { forwardedRef, ...otherProps } = this.props; |
83 | 84 | const passedProps = {
|
84 |
| - ...this.props, |
| 85 | + ...otherProps, |
85 | 86 | ...this.state,
|
86 |
| - ref: (ref) => { |
87 |
| - this.innerRef = ref; |
88 |
| - }, |
| 87 | + ref: forwardedRef, |
89 | 88 | };
|
90 | 89 |
|
91 |
| - return ( |
92 |
| - <ConnectedComponent |
93 |
| - {...passedProps} |
94 |
| - /> |
95 |
| - ); |
| 90 | + return <ConnectedComponent {...passedProps} />; |
96 | 91 | }
|
97 | 92 | }
|
98 | 93 |
|
99 | 94 | EasyConnect.displayName = getDisplayName(wrappedComponentName);
|
| 95 | + EasyConnect.WrappedComponent = WrappedComponent; |
| 96 | + |
| 97 | + if (args[3] && args[3].forwardRef) { |
| 98 | + // eslint-disable-next-line react/no-multi-comp |
| 99 | + const forwarded = forwardRef((props, ref) => ( |
| 100 | + <EasyConnect {...props} forwardedRef={ref} /> |
| 101 | + )); |
| 102 | + |
| 103 | + forwarded.displayName = wrappedComponentName; |
| 104 | + forwarded.WrappedComponent = WrappedComponent; |
| 105 | + |
| 106 | + return hoistStatics(forwarded, WrappedComponent); |
| 107 | + } |
100 | 108 |
|
101 | 109 | return hoistStatics(EasyConnect, WrappedComponent);
|
102 | 110 | };
|
0 commit comments