【发布时间】:2021-03-12 11:15:34
【问题描述】:
我正在尝试设置材质 UI 组件的样式,这是我的代码:
export const CardContentStyled = styled(CardContent)`
width: ${props => (props.isNarrow ? 'calc(100% - 60px)' : 'calc(100% - 200px)')};
box-sizing: border-box;
position: relative;
padding: 0 60px;
`;
然后从组件中将所有内容导入为 ui 并像这样使用它:
<ui.CardContentStyled isNarrow={isNarrow}>
whatever
</ui.CardContentStyled>
它有效,但我收到此错误:
警告:React 无法识别 DOM 元素上的 isNarrow 属性。如果您有意希望它作为自定义属性出现在 DOM 中,请将其拼写为小写 isnarrow。如果您不小心从父组件传递了它,请将其从 DOM 元素中移除。
我尝试了在这里找到的所有东西,我认为唯一有效的是:
React does not recognize the `isActive` prop on a DOM element - styled-components
但这似乎有点hacky,也许有更好的方法。
【问题讨论】:
标签: javascript reactjs styled-components