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'> OP extends Omit<P, 'className' | 'style'> = Omit<P, 'className' | 'style'>
>( >(
OriginComponent: React.ComponentType<OP>, OriginComponent: React.ComponentType<OP>,
config: { cacheId: string | ((props: OP) => string) } config: {
cacheId: string | ((props: OP) => string);
}
) { ) {
// eslint-disable-next-line react/display-name // eslint-disable-next-line react/display-name
return (props: P) => { return (props: P) => {
@ -32,7 +34,7 @@ export function withKeepAliveOverlay<
} }
return config.cacheId; return config.cacheId;
}, []); }, [originProps]);
useEffect(() => { useEffect(() => {
mount(cacheId, <OriginComponent key={cacheId} {...originProps} />); mount(cacheId, <OriginComponent key={cacheId} {...originProps} />);
@ -40,7 +42,7 @@ export function withKeepAliveOverlay<
return () => { return () => {
hide(cacheId); hide(cacheId);
}; };
}, []); }, [cacheId]);
useEffect(() => { useEffect(() => {
if (!containerRef.current) { if (!containerRef.current) {
@ -72,7 +74,7 @@ export function withKeepAliveOverlay<
resizeObserver.unobserve(containerRef.current); resizeObserver.unobserve(containerRef.current);
} }
}; };
}, []); }, [cacheId]);
return ( return (
<div <div

Loading…
Cancel
Save