材料UI+用道具抛出的样式“ React”无法识别DOM元素上的Zindex Prop。
我正在努力争论错误 - > React无法在DOM元素上识别Zindex Prop。
当我使用MUI组件并用道具设计时,它会发生。
代码示例:
样式:
import {Drawer as DrawerBase, styled} from '@material-ui/core'
interface DrawerProps {
zIndex: number
}
export const Drawer = styled(DrawerBase)<Theme, DrawerProps>(({zIndex}) => ({
zIndex
}))
实现:
<Drawer zIndex={10} />
我正在使用: “@Material-ui/core”:“^4.12.3”
是否有可能防止将道具传递给DOM元素?
I'm struggling with React error -> React does not recognize zIndex prop on a DOM element.
It happens when I'm using MUI component and Styled with props.
Code example:
styled:
import {Drawer as DrawerBase, styled} from '@material-ui/core'
interface DrawerProps {
zIndex: number
}
export const Drawer = styled(DrawerBase)<Theme, DrawerProps>(({zIndex}) => ({
zIndex
}))
implementation:
<Drawer zIndex={10} />
I'm using:
"@material-ui/core": "^4.12.3"
Is there any possibility to prevent passing props to DOM elements?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不幸的是,材料UI的“样式”语法令人困惑。但是,这应该起作用:
“应该ForwardProp”也是一个不幸的名称,因为听起来像属性Zindex并未转发,但实际上可以访问。
希望它有帮助。
Material UI's 'styled' syntax is very confusing unfortunately. This should work though:
'shouldForwardProp' is also an unfortunate name as it sounds like the property zIndex isn't forwarded, but it is actually accessible.
Hope it helps.
我以前从未在MUI中使用过样式的组件,所以请用一粒盐来做什么。但是我有一些想法:
您是从
'@youteral-ui/core'
导入样式
,但是您正在调用style> style
功能(没有“ D”)。查看 MUI文档使用样式组件使用它的方式,我们传统上使用了使用CSS语法的样式组件。我希望您的代码看起来像这样:
DOM元素需要“ z index”,而不是“ zindex”。
您的代码段还具有带有您的
const抽屉
的错字,其中您已经排除了“ S”:cont
。希望这会有所帮助。
I've not used styled components within MUI before, so take what I'm saying with a grain of salt. But I have a few ideas:
You're importing
styled
from'@material-ui/core'
, but you're calling astyle
function (without the "d").Looking at the MUI docs for using styled components, they're using it the way we traditionally use styled components, which is using CSS syntax. I'd expect your code to look like this:
The DOM element needs "z-index", not "zIndex".
Your code snippet also has a typo with your
const Drawer
where you've left out the "s":cont
.Hopefully this helps.