fix: 优化withKeepAliveOverlay的参数依赖管理,修复不强制渲染时无法取消挂载的情况

pull/64/head
moonrailgun 3 years ago
parent 4e21735d7b
commit 42e004ce20

@ -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) => {
@ -32,7 +34,7 @@ export function withKeepAliveOverlay<
}
return config.cacheId;
}, []);
}, [originProps]);
useEffect(() => {
mount(cacheId, <OriginComponent key={cacheId} {...originProps} />);
@ -40,7 +42,7 @@ export function withKeepAliveOverlay<
return () => {
hide(cacheId);
};
}, []);
}, [cacheId]);
useEffect(() => {
if (!containerRef.current) {
@ -72,7 +74,7 @@ export function withKeepAliveOverlay<
resizeObserver.unobserve(containerRef.current);
}
};
}, []);
}, [cacheId]);
return (
<div

Loading…
Cancel
Save