问题描述
我已经将react-jss
和material-ui
一起使用了一段时间. material-ui 3.x-> 4.x迁移指南指出MUI 4与React JSS 9.x不兼容:
I've used react-jss
with material-ui
for a while now. The material-ui 3.x -> 4.x migration guide says that MUI 4 isn't compatible with React JSS 9.x:
https://material-ui.com/guides/migration-v3/
此外,看来react-jss
项目已存档:
Furthermore, it looks like the react-jss
project has been archived:
https://github.com/cssinjs/react-jss
...但是JSS的版本至少为10:
...but JSS is up to at least version 10:
https://cssinjs.org/?v=v10.0.0-alpha .16
因此,我对如何在MUI 4中使用React-JSS感到完全困惑.package.json
中的导入不是"react-jss": "8.6.1",
吗?我应该切换到情感"还是样式化组件"?如此困惑.
So I'm completely confused on how to use React-JSS with MUI 4. Is the import something other than "react-jss": "8.6.1",
in package.json
? Should I switch to Emotion or Styled Components? So confused.
推荐答案
您可以使用:
"react-jss": "10.0.0-alpha.16"
https://github.com/cssinjs/react-jss 被存档是因为将其重组为jss monorepo(一个GitHub存储库中的多个软件包)的一部分: https://github.com/cssinjs/jss/tree/master/packages/react-jss .
https://github.com/cssinjs/react-jss is archived because of it being restructured to be part of the jss monorepo (multiple packages in one GitHub repository): https://github.com/cssinjs/jss/tree/master/packages/react-jss.
每当升级Material-UI时,都应检查Material-UI中的jss版本是否已更改,以便可以保持同步;否则,您将引入两个版本的jss.您可以在此处检查Material-UI jss版本: https://github.com/mui-org/material-ui/blob/master/packages/material-ui-styles/package.json#L48
Whenever you upgrade Material-UI, you should check to see if the jss version in Material-UI has changed so that you can stay in sync; otherwise you'll be pulling in two versions of jss. You can check the Material-UI jss version here: https://github.com/mui-org/material-ui/blob/master/packages/material-ui-styles/package.json#L48
您还应该研究在Material-UI中是否需要直接使用react-jss与仅使用jss包装器(例如withStyles
,makeStyles
等).
You should also look into whether you need to be using react-jss directly vs. just using the jss wrappers in Material-UI (e.g. withStyles
, makeStyles
, etc.).
这篇关于如何在MaterialUI 4中使用react-jss?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!