reactjs - 如何将 component 属性与自定义组件一起使用?
问题描述
我正在尝试将 Link 组件(来自 react-router)与我的自定义按钮组件一起使用。我不确定我做错了什么:
<Button component={Link} to="/">
"This works"
</Button>
<CustomButton component={Link} to="/">
"And this doesn't"
</CustomButton>
CustomButton 是一个简单的 withStyles - 组件:
const CustomButton = withStyles((theme: Theme) => ({
root: {
marginLeft: '0.5rem'
/* ...etc ... */
},
}))((props: ButtonProps) => <Button color="default" {...props} variant="contained" />);
export default CustomButton;
我收到类型错误:
'IntrinsicAttributes & Pick、"button">、"children" 类型不存在属性'component' | "参考" | “表格” | “插槽” | ...
沙盒:https ://codesandbox.io/s/fervent-borg-bqize
它本身确实有效,但是来自 linter 的类型错误不允许我编译它(不抑制 linter)
解决方案
尝试
const CustomButton = withStyles({
root: {
marginLeft: '0.5rem'
}
})(Button);
推荐阅读
- matlab - 获取音频的基频和谐波
- java - 没有使用自定义适配器调用 setOnItemClickListener
- hive - Hive ORC 上的 Presto 查询错误,无法从 DOUBLE 类型的 ORC 流中读取真实的 SQL 类型
- sql - 对子查询 Bigquery 进行分组和平均
- linux - InputOnly 窗口的 XCreateWindow 上的 BadMatch 错误
- php - 为什么 PHP POST 方法在 mac 上不起作用?
- http - API 总是错误 408 - 发送的数据类型无效
- php - Preg_match 正在截断数组中的最后一个元素
- python - Pandas:如何根据另一列中的元素数量增加一列中的元素?
- flutter - 使用 GN 构建系统,如何将 cflag 设置为目标中的特定源文件