【问题标题】:React material-ui MenuItem containerElement not working反应材料-ui MenuItem containerElement不起作用
【发布时间】:2017-09-02 11:00:27
【问题描述】:

我有以下代码:

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

但它不能像这里Material UI Menu using routes 讨论的 MenuItem 的其他主题/线程中解释的那样工作。 一旦我将 containerElement 道具添加到 MenuItem 我得到这个异常:

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

【问题讨论】:

  • 如何导入您的Link
  • 这是导入import Link from 'react-router';
  • 不确定这是主要问题,但应该是import { Link } from 'react-router';

标签: reactjs react-router material-ui


【解决方案1】:

看起来不再有效(需要查找更改日志。)

为了解决这个问题,我做了 npm install react-router-dom --save 并使用了以下 sn-p:

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>

【讨论】:

    猜你喜欢
    • 2018-11-08
    • 2020-11-29
    • 2022-01-04
    • 1970-01-01
    • 2020-10-29
    • 2020-12-02
    • 1970-01-01
    • 2021-08-11
    • 2021-06-23
    相关资源
    最近更新 更多