首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MUI5 :无法读取未定义的属性(读取“主”)

MUI5 :无法读取未定义的属性(读取“主”)
EN

Stack Overflow用户
提问于 2022-02-27 15:07:39
回答 1查看 808关注 0票数 0

我使用的是带有reactjs的MUI5,我想使用makeStyles向MUI组件添加一些自定义的CSS,但它不允许我在MUI样式中使用默认主题,所以我的代码如下:

代码语言:javascript
复制
import { Grid, Card, CardContent,Typography, CardActions,Button, AppBar, Toolbar, 
Box,IconButton, Menu, MenuItem, InputBase, alpha, styled, Badge, Container, CardHeader, 
CardMedia  } from '@mui/material';
import EmailIcon from '@mui/icons-material/Email';
import NotificationsIcon from '@mui/icons-material/Notifications';

import React from 'react' 

import { makeStyles } from '@mui/styles'
const useStyles = makeStyles((theme) => ({
  root: ({
    backgroundColor: theme.palette.primary.light,
    color: theme.color,
  }),
}));
const App = () => {
  const classes = useStyles();
  return(
    <Fragment>
      <Container className={classes.root}>
        <Typography>
          this is a very random text to fill
        </Typography>
      </Container>
    </Fragment>
  )
}

 export default App;

它不允许我进入主题道具里面的造型机

EN

回答 1

Stack Overflow用户

发布于 2022-02-27 15:51:19

首先,尝试将"root“赋值为普通对象属性,如下所示-

代码语言:javascript
复制
const useStyles = makeStyles((theme) => ({
  root: {
    backgroundColor: theme.palette.primary.light,
    color: theme.color,
  }
})); 

如果它不起作用,您可能想看看这个- https://mui.com/styles/basics/#using-the-theme-context

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71285885

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档