[英]How to properly use MaterialUI icons in CoreUI React
I need to use Material UI icons in a React dashboard template of CoreUI, for that, i installed @mui/material
and @mui/icons-material
with:我需要在 CoreUI 的 React 仪表板模板中使用 Material UI 图标,为此,我安装了
@mui/material
和@mui/icons-material
:
npm install @mui/material @emotion/react @emotion/styled
And和
npm install @mui/icons-material
This is my package.json now:这是我的package.json现在:
"dependencies": {
"@coreui/chartjs": "^3.0.0",
"@coreui/coreui": "^4.2.1",
"@coreui/icons": "^2.1.0",
"@coreui/icons-react": "^2.1.0",
"@coreui/react": "^4.4.0",
"@coreui/react-chartjs": "^2.1.0",
"@coreui/utils": "^1.3.1",
"@emotion/react": "^11.10.4",
"@emotion/styled": "^11.10.4",
"@mui/icons-material": "^5.10.6",
"@mui/material": "^5.10.6"
//...
}
Then in the src/_nav.js
file, there where should i import the icon and use it.然后在
src/_nav.js
文件中,我应该在哪里导入图标并使用它。 So i tried this code below:所以我在下面尝试了这段代码:
import React from 'react'
import CIcon from '@coreui/icons-react'
import { CNavItem } from '@coreui/react'
import PeopleIcon from '@mui/icons-material/People'
const _nav = [
{
component: CNavItem,
name: 'Users',
to: '/theme/colors',
icon: <CIcon icon={PeopleIcon} customClassName="nav-icon" />,
},
]
export default _nav
Now the NPM in terminal shows Compiled successfully!
现在终端中的 NPM 显示
Compiled successfully!
but i'm getting a blank page with this error in console.dev:但是我在console.dev中得到了一个带有此错误的空白页:
Uncaught Error: Cannot find module '@emotion/react'
未捕获的错误:找不到模块“@emotion/react”
first of all, it's recommanded that you restart your npm terminal after installing new package.首先,建议您在安装新的 package 后重新启动 npm 终端。
Secondly, you can't implement materialUI icon in the same way you use CoreUi icons.其次,不能像使用 CoreUi 图标一样实现 materialUI 图标。 You have to use
icon: <PeopleIcon />,
instead of icon: <CIcon icon={PeopleIcon} customClassName="nav-icon" />,
.您必须使用
icon: <PeopleIcon />,
而不是icon: <CIcon icon={PeopleIcon} customClassName="nav-icon" />,
。
import React from 'react'
import CIcon from '@coreui/icons-react'
import { CNavItem } from '@coreui/react'
import PeopleIcon from '@mui/icons-material/People'
const _nav = [
{
component: CNavItem,
name: 'Users',
to: '/theme/colors',
icon: <PeopleIcon />,
},
]
export default _nav
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.