Skip to content

Commit

Permalink
fix: 优化withKeepAliveOverlay的参数依赖管理,修复不强制渲染时无法取消挂载的情况
Browse files Browse the repository at this point in the history
  • Loading branch information
moonrailgun committed Dec 18, 2022
1 parent 4e21735 commit 42e004c
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ export function withKeepAliveOverlay<
OP extends Omit<P, 'className' | 'style'> = Omit<P, 'className' | 'style'>
>(
OriginComponent: React.ComponentType<OP>,
config: { cacheId: string | ((props: OP) => string) }
config: {
cacheId: string | ((props: OP) => string);
}
) {
// eslint-disable-next-line react/display-name
return (props: P) => {
Expand All @@ -32,15 +34,15 @@ export function withKeepAliveOverlay<
}

return config.cacheId;
}, []);
}, [originProps]);

useEffect(() => {
mount(cacheId, <OriginComponent key={cacheId} {...originProps} />);

return () => {
hide(cacheId);
};
}, []);
}, [cacheId]);

useEffect(() => {
if (!containerRef.current) {
Expand Down Expand Up @@ -72,7 +74,7 @@ export function withKeepAliveOverlay<
resizeObserver.unobserve(containerRef.current);
}
};
}, []);
}, [cacheId]);

return (
<div
Expand Down

0 comments on commit 42e004c

Please sign in to comment.