自定义道具在材料-UI组件中无法使用
我想在MUI按钮中添加(背景& color)自定义道具,例如:
<ButtonCustom bg="#6415ff" color="#f7fafc">Sign Up</ButtonCustom>
<ButtonCustom bg="#e2e8f0" color="#4a5568">Search</ButtonCustom>
文件:buttoncustom.js,
import Button from "@mui/material/Button";
import { styled } from "@mui/system";
const ButtonStyled = styled(Button)`
background-color: ${({ bg }) => bg};
color: ${({ color }) => color};
padding: 16px 0;
&:hover {
background-color: #5011cc;
}
font-size: 16px;
width: 12rem;
`;
export default ButtonStyled;
但它会给我这个错误:
TypeError
Cannot read properties of undefined (reading 'main')
所以我的问题是:我如何添加多个自定义道具?
非常感谢您给我时间并回答这个问题。
i want to add ( background & color ) custom props, to the mui button, like this:
<ButtonCustom bg="#6415ff" color="#f7fafc">Sign Up</ButtonCustom>
<ButtonCustom bg="#e2e8f0" color="#4a5568">Search</ButtonCustom>
file: ButtonCustom.js
import Button from "@mui/material/Button";
import { styled } from "@mui/system";
const ButtonStyled = styled(Button)`
background-color: ${({ bg }) => bg};
color: ${({ color }) => color};
padding: 16px 0;
&:hover {
background-color: #5011cc;
}
font-size: 16px;
width: 12rem;
`;
export default ButtonStyled;
But it will give me this error:
TypeError
Cannot read properties of undefined (reading 'main')
so my question is : how can i add more than one custom props??
Thank you very much for giving me time and answering this question.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论