reactjs - 样式化组件属性分配中的以下代码有什么区别?
问题描述
在下面的1和2之间,将属性分配给HTML元素有什么区别?我用了2,它突然停止工作。1 似乎工作正常。我不知道为什么 2 不再工作了?
使用 1 时出现的错误是:
Invalid value for prop size on the tag <input>. Either remove them from the element or pass a string or number value to them in the DOM
//1
const Input = styled.input.attrs(props => ({
size: props.small ? 5 : undefined,
}))`
//2
const Input = styled.input.attrs({
size: (props) => props.small ? 5 : undefined,
}))`
解决方案
推荐阅读
- python - 有没有办法在 Python 中向后读取一行?
- c# - 将 WF 控件转换为圆角和更好看的最简单方法
- next.js - 如何在 Next.js 应用程序中实例化和使用 Chirp WebAssembly SDK?
- netlogo - 如何在 NetLogo 中识别一群乌龟?
- javascript - 外部供应商脚本(JS,Jquery)在 ReactJS 中渲染后不起作用
- xml - 使用 Xquery 计算元素并返回元素名称和值
- javascript - 阻止 Enter 在 Safari 中提交表单
- java - 在 PositionalDataSource 中未调用 loadInitial 方法
- c# - 数据的反映
- html - 有没有可能删除?和 = 在 html 中?