通过containerElement prop将NavLink传递给Material UI组件会出现"Failed prop type"警告

Doc*_*son 3 reactjs react-router material-ui

<RaisedButton containerElement={NavLink} to="/somewhere">
   Somewhere
</RaisedButton>
Run Code Online (Sandbox Code Playgroud)

产生以下警告:

Warning: Failed prop type: Invalid prop `containerElement` supplied to `RaisedButton`.
in RaisedButton (at App.js:11)
in App (at index.js:23)
in Provider (at index.js:22)
in MuiThemeProvider (at index.js:21)
Run Code Online (Sandbox Code Playgroud)

但Navlink正确呈现并重定向到/somewhere点击.如果这是一个仍然有效的弃用道具,那么我无法找到新道具的名称......请指教.如果没有别的我想隐藏警告(如何?).

hax*_*nel 16

从Material UI 1.0开始,prop被称为component:

import { Link } from 'react-router-dom'
import Button from 'material-ui/Button';

<Button component={Link} to="/open-collective">
  Link
</Button>
Run Code Online (Sandbox Code Playgroud)

更多关于按钮.

  • 我不敢相信反应团队现在强制执行此react.fowardref,他们知道因此需要在代码中更改多少内容吗? (2认同)

Mik*_*kel 4

我认为您需要为其提供类似containerElement这样的标记(而不仅仅是元素的名称)

containerElement={<NavLink to="/home" />}
Run Code Online (Sandbox Code Playgroud)

尝试一下,看看是否有效