react-router-dom - styled-components:如何防止道具被发送到链接组件?
问题描述
我正在使用样式化组件来设置我的链接样式。我有时还需要使用Link
来自react-router-dom
.
import { Link } from 'react-router-dom';
import { Anchor } from './src';
export const StyledLink = Anchor.withComponent(Link);
但是,上面的代码会在控制台中产生以下警告:
警告:收到
true
非布尔属性unstyled
。如果要将其写入 DOM,请改为传递字符串:unstyled="true" 或 unstyled={value.toString()}。
unstyled
是一个被传递给StyledLink
这样的道具:
<StyledLink unstyled />
这个警告是由Link
组件生成的,是因为unstyled
prop 被传递给 DOM 元素Link
。
所以,问题是,如何防止Link
尝试向元素添加道具?
解决方案
推荐阅读
- javascript - 无法使用 axios 从 firebase 数据库中删除数据
- c# - 如何使用 Graph API 设置主 SMTP 地址?
- rest - Codeigniter 301 永久移动
- javascript - 如何在按钮单击时水平添加输入框
- c# - 将位图转换为 ImageSource 后资源 png 质量下降
- php - 如果业务逻辑要发送电子邮件
- c# - 使用 VS 2019 生成 SOAP 客户端时如何配置端点?
- c# - 替换字符串语句中的匹配字符串c#
- django - 模板渲染期间出错:__str__ 返回非字符串(NoneType 类型)
- angular - 角度超过最大调用堆栈大小