Meaning of React LinkProps



我认为LinkProps是一种道具,但我不知道指定Omit<RouterLinkProps,"到">。请告诉我。

import { Link as RouterLink, LinkProps as RouterLinkProps } from 'react-router-dom';
import { LinkProps } from '@mui/material/Link';
const LinkBehavior = React.forwardRef<
HTMLAnchorElement,
Omit<RouterLinkProps, 'to'> & { href: RouterLinkProps['to'] }
>((props, ref) => {
const { href, ...other } = props;
// Map href (MUI) -> to (react-router)
return <RouterLink ref={ref} to={href} {...other} />;
});

参考站点:。https://mui.com/material-ui/guides/routing/

Omit<RouterLinkProps, 'to'>只是从react-router-domLink组件的props类型定义中删除toprop。有关详细信息,请参阅省略键。

LinkProps

export interface LinkProps
extends Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, "href"> {
reloadDocument?: boolean;
replace?: boolean;
state?: any;
to: To; // <-- removes this prop
}

该类型的其余部分有效地将to道具移动到href道具。

Omit<RouterLinkProps, 'to'> & { href: RouterLinkProps['to'] }

这应该导致如下类型:

export interface LinkProps
extends Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, "href"> {
reloadDocument?: boolean;
replace?: boolean;
state?: any;
href: To;
}

最新更新