将材料ui项目从v0.20升级到v1

时间:2020-01-10 16:21:40

标签: reactjs material-ui upgrade

对我们的项目而言,至少将材料用户界面版本至少最初升级到版本1是必不可少的。我们的项目规模不断扩大,而当前版本使我们遇到了问题。我们当前的版本是v0.20.2,您看到的版本确实很旧 我遵循https://material-ui.com/guides/migration-v0x/,但发生以下错误:

    Uncaught Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app
See httpsinvalid-hook-call for tips about how to debug and fix this problem.
    at resolveDispatcher (react.development.js:1590)
    at useMemo (react.development.js:1642)
    at Provider (Provider.js:10)
    at mountIndeterminateComponent (react-dom.development.js:8032)
    at beginWork (react-dom.development.js:8221)
    at performUnitOfWork (react-dom.development.js:10224)
    at workLoop (react-dom.development.js:10288)
    at HTMLUnknownElement.callCallback (react-dom.development.js:542)
    at Object.invokeGuardedCallbackDev (react-dom.development.js:581)
    at invokeGuardedCallback (react-dom.development.js:438)

我的package.json是这样的:

"dependencies": {
    "@material-ui/codemod": "^4.5.0",
    "@material-ui/core": "^1.0.0",
    "@material-ui/icons": "^4.5.1",
    "@material-ui/styles": "^4.8.2",
    "babel-polyfill": "~6.22.0",
    "browser-filesaver": "~1.1.1",
    "build-url": "~1.2.0",
    "es6-promise": "~4.2.5",
    "file-saver": "~2.0.1",
    "iban": "~0.0.8",
    "immutable": "~3.8.2",
    "jsdoc": "^3.6.3",
    "jsdoc-api": "~3.0.0",
    "loaders.css": "~0.1.2",
    "material-ui": "^0.20.2",
    "moment": "~2.20.1",
    "prop-types": "~15.6.0",
    "react": "^16.12.0",
    "react-datepicker": "~0.48.0",
    "react-dom": "^16.2.1",
    "react-feature-toggles": "~3.0.3",
    "react-intl": "~2.4.0",
    "react-loaders": "~3.0.1",
    "react-redux": "^7.1.3",
    "react-router": "~3.2.0",
    "react-tooltip": "~3.10.0",
    "redux": "~3.7.2",
    "redux-form": "~8.1.0",
    "redux-form-material-ui": "~4.3.3",
    "redux-immutable": "~4.0.0",
    "redux-persist": "~4.8.0",
    "redux-persist-immutable": "~4.3.1",
    "redux-saga": "~0.15.3",
    "whatwg-fetch": "~2.0.1"
  },

有人成功从0.20.2升级到Material ui v1吗?如果是这样的话 您遵循的确切步骤? 预先感谢

1 个答案:

答案 0 :(得分:1)

您有reactreact-dom的不同版本。您使用的react-dom版本(16.2.1)不支持钩子。您应该将其更改为与react版本(16.12.0)相同。