小编Mad*_*ghe的帖子

Mui v5.0.4 makeStyles、withStyles 不会将样式应用于 mui 组件

我目前正在开发一个使用 Mui v5.0.4 的 React (v.17) 项目。我已经在需要的地方编写了自定义样式,并且一切都按预期工作。几天后,我开始处理同一个项目,当我启动应用程序时,我编写的样式没有按预期显示。这种情况发生在特定组件中,例如版式、按钮。我彻底检查了我的代码,尝试了不同的浏览器和计算机,但没有成功。

我创建了一个新项目,看看问题是否仅限于前一个项目,但情况似乎也并非如此。我将在下面发布该应用程序的代码片段以供参考。

应用程序.js

import React from 'react';

import Something from './something/Something';

function App() {
  return <Something />;
}

export default App;
Run Code Online (Sandbox Code Playgroud)

Something.js

import React from 'react';
import PropTypes from 'prop-types';
import { Typography } from '@mui/material';
import { withStyles } from '@mui/styles';

import styles from './Something.styles';

const Something = ({ classes }) => {
  return <Typography className={classes.something}>Something</Typography>;
};

Something.propTypes = {
  classes: PropTypes.object.isRequired
};

export default withStyles(styles)(Something);
Run Code Online (Sandbox Code Playgroud)

Something.styles.js

const styles = (theme) => ({ …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs material-ui

6
推荐指数
1
解决办法
6451
查看次数

标签 统计

javascript ×1

material-ui ×1

reactjs ×1