如何从 Material UI 导入 makeStyles?

Ras*_*rov 17 reactjs material-ui

我使用的是 Material UI 版本 5.2.7。当我从 导入 makeStyles 时@mui/materials/styles,出现以下错误 -

Uncaught Error: MUI: makeStyles is no longer exported from @mui/material/styles. You have to import it from @mui/styles. See https://mui.com/r/migration-v4/#material-ui-core-styles for more details.

它还说@mui/styles在 Material UI 版本 5 中已弃用。所以我对如何导入 makeStyles 感到困惑。有人对此有任何想法吗?

Wra*_*thy 20

正如您在文档中看到的,现在在 Material UI 中不推荐使用 makeStyles 作为一个概念,因为他们不想再使用 JSS,而是建议使用emotion/react库或styled components.


Dus*_*san 9

您可以在功能组件内创建带有样式( style={your styles} )的对象,然后在该功能组件内的 MUI 组件上使用 sx 属性( sx={style} ),而不是 makeStyles 。