反应material-ui MenuItem containerElement不起作用 [英] React material-ui MenuItem containerElement not working
本文介绍了反应material-ui MenuItem containerElement不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码:
<MenuItem primaryText="home" containerElement={<Link to="/" />} />
但是,它不能按菜单主题在此处讨论的其他主题/线程中的解释进行操作,如材料使用路线的UI菜单. 一旦我将containerElement prop添加到MenuItem,我就会收到此异常:
But it doesn't work as explained in other topics/threads where MenuItem discussed like here Material UI Menu using routes. Once i add containerElement prop to MenuItem i'm getting this exception:
Uncaught Error:
Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined.
You likely forgot to export your component from the file it's defined in.
Check the render method of `EnhancedButton`.
推荐答案
它似乎不再起作用(将需要查找更改日志.)
It looks like that no longer works (will need to find the change log.)
要解决此问题,我做了npm install react-router-dom --save
并使用了以下代码段:
To fix this I did npm install react-router-dom --save
and used the following snippet:
import React, { Component } from 'react';
import { NavLink } from 'react-router-dom'
import Menu from 'material-ui/Menu';
import MenuItem from 'material-ui/MenuItem';
import Drawer from 'material-ui/Drawer'
<Drawer
docked={false}
open={this.state.open}
onRequestChange={(open) => this.setState({open})}>
<MenuItem onTouchTap={() => {this.handleClose()}} >
<NavLink to="/">Home </NavLink>
</MenuItem>
<MenuItem onTouchTap={() => {this.handleClose() }} >
<NavLink to="/about"> About Us </NavLink>
</MenuItem>
</Drawer>
这篇关于反应material-ui MenuItem containerElement不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文