我正在使用material-ui v3.5.1
我想让 ListItem 使用 Link 组件,如下所示:
<ListItem component={Link} to="/some/path">
<ListItemText primary="Text" />
</ListItem>
但是 Typescript 向我显示了一条冗长的错误消息(“组件”一词在 VSCode 中突出显示),底部显示:
The type "typeof Link" cannot be assigned to the type "ComponentClass<ListItemProps, any>"
Property 'to' is missing in type 'ListItemProps' but required in type 'Readonly'. [2322]
是否有解决方法可以使此类内容与 Typescript 一起使用?
Thanks!
这是目前我们类型声明的限制(直到我们转向通用属性)。作为临时解决方法,您可以将链接提取到另一个组件中,例如
function SomePathLink(props: ButtonBaseProps) {
return <Link to="/some/path" {...props} />
}
<ListItem component={SomePathLink}>
<ListItemText primary="Text" />
</ListItem>
文档中更详细的解释:https://material-ui.com/demos/buttons/#third-party-routing-library https://material-ui.com/demos/buttons/#third-party-routing-library
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)