gpt4 book ai didi

reactjs - Material UI withStyles : Invalid prop `component` of type `object` supplied to `Route` , 预期 `function`

转载 作者:行者123 更新时间:2023-12-05 07:17:33 25 4
gpt4 key购买 nike

当我尝试使用使用 material-ui withStyles 功能导出的组件时,我收到此警告,如下所示:

export default withStyles(styles)(MyComponent)

然后像这样将它传递给 ReactRouter:

import MyComponentfrom './MyComponent'
<Route path="/my-component" component={MyComponent} />

组件正在按预期呈现并且运行良好,但警告让我很困扰。

有人可以解释为什么我会收到这个吗?

更新 1(添加警告): Warning

最佳答案

我怀疑您使用的是 4.3.1 或更早版本的 react-router。

这在 Route 中使用 component: PropTypes.func .

随着 React.forwardRef(在 Material-UI v4 中被大量使用)和 React 16.8 中引入的其他特性(hooks)的引入,可能有一个组件类型不是一个函数。

从 react-router 4.4 版开始,它使用 isValidElementType .这可以正确识别 forwardRef 和其他方法返回的组件类型。

相关回答:I'm getting error after upgrading to Material UI 4 - withStyles

关于reactjs - Material UI withStyles : Invalid prop `component` of type `object` supplied to `Route` , 预期 `function`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58751873/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com