Skip to content

Commit 42e004c

Browse files
committed
fix: 优化withKeepAliveOverlay的参数依赖管理,修复不强制渲染时无法取消挂载的情况
1 parent 4e21735 commit 42e004c

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

client/web/src/components/KeepAliveOverlay/withKeepAliveOverlay.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ export function withKeepAliveOverlay<
1919
OP extends Omit<P, 'className' | 'style'> = Omit<P, 'className' | 'style'>
2020
>(
2121
OriginComponent: React.ComponentType<OP>,
22-
config: { cacheId: string | ((props: OP) => string) }
22+
config: {
23+
cacheId: string | ((props: OP) => string);
24+
}
2325
) {
2426
// eslint-disable-next-line react/display-name
2527
return (props: P) => {
@@ -32,15 +34,15 @@ export function withKeepAliveOverlay<
3234
}
3335

3436
return config.cacheId;
35-
}, []);
37+
}, [originProps]);
3638

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

4042
return () => {
4143
hide(cacheId);
4244
};
43-
}, []);
45+
}, [cacheId]);
4446

4547
useEffect(() => {
4648
if (!containerRef.current) {
@@ -72,7 +74,7 @@ export function withKeepAliveOverlay<
7274
resizeObserver.unobserve(containerRef.current);
7375
}
7476
};
75-
}, []);
77+
}, [cacheId]);
7678

7779
return (
7880
<div

0 commit comments

Comments
 (0)