fix: PageHeader state update error (#33546)

This commit is contained in:
Wuif 2022-01-04 15:28:09 +01:00 committed by GitHub
parent ef51e4eb78
commit cf5eac1a8c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -9,6 +9,7 @@ import Breadcrumb, { BreadcrumbProps } from '../breadcrumb';
import Avatar, { AvatarProps } from '../avatar';
import TransButton from '../_util/transButton';
import LocaleReceiver from '../locale-provider/LocaleReceiver';
import useDestroyed from '../_util/hooks/useDestroyed';
export interface PageHeaderProps {
backIcon?: React.ReactNode;
@ -121,8 +122,11 @@ const renderChildren = (prefixCls: string, children: React.ReactNode) => (
const PageHeader: React.FC<PageHeaderProps> = props => {
const [compact, updateCompact] = React.useState(false);
const isDestroyed = useDestroyed();
const onResize = ({ width }: { width: number }) => {
updateCompact(width < 768);
if (!isDestroyed()) {
updateCompact(width < 768);
}
};
return (
<ConfigConsumer>