首页 > 解决方案 > 失败的道具类型:ForwardRef(Button):道具类型`component`无效:React中带有材料ui的警告

问题描述

我有一个简单的 React 代码,只需从材料 ui 中放置一个按钮。但我得到了下一个警告:

Warning: Failed prop type: ForwardRef(Button): prop type `component` is invalid; it must be a function, usually from the `prop-types` package, but received `undefined`.
    in ForwardRef(Button) (created by WithStyles(ForwardRef(Button)))
    in WithStyles(ForwardRef(Button)) (at App.js:12)

如何解决?

我的完整代码:

import React from 'react';
import Button from '@material-ui/core/Button';

const App = props => {
  return (
    <div className="App">
      <Button variant="contained" color="primary">
        Hello World
      </Button>
    </div>
  );
};

export default App;

UPD:我的 package.json 文件。乍一看,我不使用任何其他 prop-types 包

{
...
  "dependencies": {
    "@material-ui/core": "^4.4.2",
    "@material-ui/icons": "^4.4.1",
    "connected-react-router": "^6.5.2",
    "history": "^4.10.1",
    "react": "^16.9.0",
    "react-cookie": "^4.0.1",
    "react-dom": "^16.9.0",
    "react-redux": "^7.1.1",
    "react-router": "^5.0.1",
    "react-router-dom": "^5.0.1",
    "react-scripts": "3.1.1",
    "redux": "^4.0.4",
    "redux-saga": "^1.0.5"
  },
  "scripts": {
...
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
...
    ],
    "development": [
        ....
    ]
  }

标签: reactjsmaterial-ui

解决方案


推荐阅读