我有以下代码
import {Button,ButtonProps} from '@mui/material';
import { alpha, styled } from '@mui/material/styles';
import { Link as RouterLink } from 'react-router-dom';
const BackButton = styled(Button)<ButtonProps>(({ theme }) => ({
borderColor: alpha(theme.palette.text.primary, 0.5),
padding: theme.spacing(1),
}));
和
const backButton = (
<BackButton
to={'/my/path'}
component={RouterLink}
fullWidth
variant="outlined"
color="inherit"
>
Back
</BackButton>
);
我有一个to
道具的打字错误,我该如何修复它?
TS2322: Type '{ children: string; to: string; component: typeof Link; fullWidth: true; variant: "outlined"; color: "inherit"; }' is not assignable to type 'IntrinsicAttributes & { children?: ReactNode; classes?: Partial<ButtonClasses>; color?: "inherit" | "error" | "primary" | "secondary" | "success" | "info" | "warning"; ... 9 more ...; variant?: "text" | ... 1 more ... | "contained"; } & ... 4 more ... & { ...; }'. Property 'to' does not exist on type 'IntrinsicAttributes & { children?: ReactNode; classes?: Partial<ButtonClasses>; color?: "inherit" | "error" | "primary" | "secondary" | "success" | "info" | "warning"; ... 9 more ...; variant?: "text" | ... 1 more ... | "contained"; } & ... 4 more ... & { ...; }'.
2条答案
按热度按时间laawzig21#
请参阅MUI Typescript页面上的组件复杂功能部分。
修改已设置样式的构件,以在末端添加类型转换:
lsmepo6l2#
尝试向按钮添加onClick处理程序以处理重定向: