Commit 8c6cae22 authored by Shen Chang's avatar Shen Chang Committed by GitHub

fix(keepAlive): Fixing multiple higher-order functions to get no real components

parent 435d90d4
...@@ -55,6 +55,14 @@ export default function keepAliveDecorator({ ...@@ -55,6 +55,14 @@ export default function keepAliveDecorator({
forwardRef = false, forwardRef = false,
}: IOptions = {}) { }: IOptions = {}) {
return (Component: React.ComponentType<IComponentProps>) => { return (Component: React.ComponentType<IComponentProps>) => {
const {
WrappedComponent,
wrappedComponent,
} = Component;
if (WrappedComponent || wrappedComponent) {
Component = WrappedComponent || wrappedComponent;
}
const { const {
componentDidMount = noop, componentDidMount = noop,
componentDidUpdate = noop, componentDidUpdate = noop,
...@@ -334,8 +342,6 @@ export default function keepAliveDecorator({ ...@@ -334,8 +342,6 @@ export default function keepAliveDecorator({
} }
class ListenUpperKeepAliveContainer extends React.Component<IListenUpperKeepAliveContainerProps, IListenUpperKeepAliveContainerState> { class ListenUpperKeepAliveContainer extends React.Component<IListenUpperKeepAliveContainerProps, IListenUpperKeepAliveContainerState> {
public static displayName = `${keepAliveDisplayName}(${displayName})`;
private combinedKeepAlive: boolean; private combinedKeepAlive: boolean;
public state = { public state = {
...@@ -459,15 +465,18 @@ export default function keepAliveDecorator({ ...@@ -459,15 +465,18 @@ export default function keepAliveDecorator({
withIdentificationContextConsumer(ListenUpperKeepAliveContainer) withIdentificationContextConsumer(ListenUpperKeepAliveContainer)
); );
let NewComponent: React.ComponentType<IKeepAliveDecorativeComponentProps> = ListenUpperKeepAliveContainerHOC; let KeepAlive: React.ComponentType<IKeepAliveDecorativeComponentProps> = ListenUpperKeepAliveContainerHOC;
if (forwardRef) { if (forwardRef) {
NewComponent = React.forwardRef((props, ref) => ( KeepAlive = React.forwardRef((props, ref) => (
<ListenUpperKeepAliveContainerHOC <ListenUpperKeepAliveContainerHOC
{...props} {...props}
forwardedRef={ref} forwardedRef={ref}
/> />
)); ));
} }
return hoistNonReactStatics(NewComponent, Component);
KeepAlive.WrappedComponent = Component;
KeepAlive.displayName = `${keepAliveDisplayName}(${displayName})`;
return hoistNonReactStatics(KeepAlive, 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