[英]TypeError: Cannot read properties of undefined (reading 'main')
I'm getting above error when I try to run my below code... before using Material-UI code was working fine.. I need color radio buttons so I added Material-UI into my project.当我尝试运行下面的代码时出现上述错误......在使用 Material-UI 代码工作正常之前......我需要彩色单选按钮,所以我将 Material-UI 添加到我的项目中。 In terminal its compiling successfully but not able to run in a browser.在终端中编译成功,但无法在浏览器中运行。 Any type of help will be appreciate任何类型的帮助将不胜感激
import Radio from '@mui/material/Radio';
const GeneralComponent = () => {
const [selectedValue, setSelectedValue] = React.useState('a');
const handleChange = (event) => {
setSelectedValue(event.target.value);
};
const controlProps = (item) => ({
checked: selectedValue === item,
onChange: handleChange,
value: item,
name: 'color-radio-button-demo',
inputProps: { 'aria-label': item },
});
return(
<Radio {...controlProps('a')} color="success" />
<Radio {...controlProps('b')} color="yellow" />
<Radio {...controlProps('c')} color="red" />
<Radio {...controlProps('d')} color="default" />
<Radio
{...controlProps('e')}
sx={{
color: pink[800],
'&.Mui-checked': {
color: pink[600],
},
}}
/>
);
}
But I solved it by myself we can pass invalid (any color) colors too... but not directly in the below way但我自己解决了,我们也可以通过无效(任何颜色)colors ......但不能直接通过以下方式
{...controlProps('e')}
sx={{
color: anycolor[800],
'&.Mui-checked': {
color: anycolor[600],
},
}}
in this way这样
'red'
, 'yellow'
or 'default'
are not valid color
values of the Radio
. 'red'
、 'yellow'
或'default'
不是Radio
的有效color
值。 The prop can only accept the following value by default: prop 默认只能接受以下值:
'default' | '默认' | 'primary' | '主要' | 'secondary' | '次要' | 'error' | '错误' | 'info' | '信息' | 'success' | '成功' | 'warning' | '警告' | string细绳
For reference, see the Radio
API here .如需参考,请参阅此处的Radio
API。 If you want to extend the color, see this answer, it applies to all MUI components with the color
prop.如果要扩展颜色,请参阅此答案,它适用于所有具有color
属性的 MUI 组件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.