React material-ui MenuItem containerElement not working

岁酱吖の 提交于 2019-12-11 04:27:17

问题


I have following code:

<MenuItem primaryText="home" containerElement={<Link to="/" />} />

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`.

回答1:


It looks like that no longer works (will need to find the change log.)

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>


来源:https://stackoverflow.com/questions/43271690/react-material-ui-menuitem-containerelement-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!