[英]MUI v5: Do I need to install @emotion/react or @emotion/styled to use sx prop?
I have migrated my project from v4 to v5, I am only using sx
prop.我已将我的项目从 v4 迁移到 v5,我只使用
sx
道具。 I have not installed @emotion/react
and everything is working fine.我还没有安装
@emotion/react
,一切正常。 Is there any reason to install @emotion/react
and @emotion/styled
?是否有任何理由安装
@emotion/react
和@emotion/styled
? because I havent install it and everything is running good.因为我还没有安装它,一切运行良好。
"@mui/icons-material": "^5.0.1",
"@mui/lab": "^5.0.0-alpha.48",
"@mui/material": "^5.0.1",
If you install MUI packages without extra configuration, you're using the default style engine powered by emotion, as opposed to the other official style engine that uses styled-component which needs more setup.如果您在没有额外配置的情况下安装 MUI 包,您将使用由情绪驱动的默认样式引擎,而不是使用需要更多设置的样式组件的其他官方样式引擎。
To use the default style engine, you need to install the 2 emotion packages as outlined in the installation guide :要使用默认样式引擎,您需要安装安装指南中概述的 2 个情绪包:
npm install @mui/material @emotion/react @emotion/styled
Even when you only use the MUI icons from @mui/icons-material
package, you also need the above 2 packages as explained in this answer.即使您只使用来自
@mui/icons-material
包的 MUI 图标,您也需要上述 2 个包,如本答案所述。 The only reason I can think why you don't have any error is because you're not using any MUI components yet, or you're using some unstyled components like the UnstyledButton
which is a raw component that doesn't have any styles applied to it.我认为您没有任何错误的唯一原因是您还没有使用任何 MUI 组件,或者您正在使用一些无样式的组件,例如
UnstyledButton
,它是一个未应用任何样式的原始组件到它。
You need both of them as per the installation guide根据安装指南,您需要两者
// with npm
npm install @mui/material @emotion/react @emotion/styled
// with yarn
yarn add @mui/material @emotion/react @emotion/styled
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.