Commit 1529a7fd authored by Shen Chang's avatar Shen Chang Committed by GitHub

Fixing multiple higher-order functions to get no real components

parent 8c6cae22
...@@ -6,6 +6,14 @@ import withIdentificationContextConsumer from './withIdentificationContextConsum ...@@ -6,6 +6,14 @@ import withIdentificationContextConsumer from './withIdentificationContextConsum
import getDisplayName from './getDisplayName'; import getDisplayName from './getDisplayName';
export default function bindLifecycle<P = any>(Component: React.ComponentType<P>) { export default function bindLifecycle<P = any>(Component: React.ComponentType<P>) {
const {
WrappedComponent,
wrappedComponent,
} = Component;
if (WrappedComponent || wrappedComponent) {
Component = WrappedComponent || wrappedComponent;
}
const { const {
componentDidMount = noop, componentDidMount = noop,
componentDidUpdate = noop, componentDidUpdate = noop,
...@@ -82,7 +90,7 @@ export default function bindLifecycle<P = any>(Component: React.ComponentType<P> ...@@ -82,7 +90,7 @@ export default function bindLifecycle<P = any>(Component: React.ComponentType<P>
); );
}; };
const NewComponent = withIdentificationContextConsumer( const BindLifecycleHOC = withIdentificationContextConsumer(
({ ({
forwardRef, forwardRef,
_identificationContextProps: { _identificationContextProps: {
...@@ -109,12 +117,14 @@ export default function bindLifecycle<P = any>(Component: React.ComponentType<P> ...@@ -109,12 +117,14 @@ export default function bindLifecycle<P = any>(Component: React.ComponentType<P>
: null : null
), ),
); );
const BindLifecycle = React.forwardRef((props, ref) => (
<BindLifecycleHOC {...props} forwardRef={ref} />
));
NewComponent.displayName = `bindLifecycle(${getDisplayName(Component)})`; BindLifecycle.WrappedComponent = Component;
BindLifecycle.displayName = `bindLifecycle(${getDisplayName(Component)})`;
return hoistNonReactStatics( return hoistNonReactStatics(
React.forwardRef((props, ref) => ( BindLifecycle,
<NewComponent {...props} forwardRef={ref} />
)),
Component, Component,
); );
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment