Unable to implement Leftnav with AppBar component in material-ui

前提是你 提交于 2019-12-08 11:28:12

问题


I am having a lot of trouble trying to implement material-ui's AppBar with Leftbar as there seems to be lots of different variations on component declaration/imported dependencies syntax and components. I can't even find proper documention on http://www.material-ui.com/ about Leftnav in the first place, all they give with Appbar is a static hamburger menu example. My code is as follows:

import React, { Component } from 'react'
import { LeftNav, AppBar} from 'material-ui'
import baseTheme from 'material-ui/styles/baseThemes/lightBaseTheme'
import getMuiTheme from 'material-ui/styles/getMuiTheme'
import { Router, Route, Navigation, Link, browserHistory } from 'react-router'


export default class Header extends Component  {


  getChildContext() {
    return {muiTheme: getMuiTheme(baseTheme)};
  }

    _toggleNav(){
       this.refs.leftNav.toggle();
     }

        render() {
          const data = this.props.data
          const nav_items = data.globals.nav_items
          //Menu item links
          const menu_items = nav_items.map(( nav_item ) => {
            return (
              <span key={ 'key-' + nav_item.value }>
                <Link to={ '/' + nav_item.value }>{ nav_item.title }</Link>
              </span>
            )
          })
            return (
                <div>
                <LeftNav ref='leftNav'
                docked={false}
                menuItems={ menu_items }  />

                <AppBar   title="App Bar Example" onLeftIconButtonTouchTap={this._toggleNav}
            isInitiallyOpen={true} />
                </div>
            )
        }
    }

    Header.childContextTypes = {
  muiTheme: React.PropTypes.object.isRequired,
};

I am getting to obscure errors which explain me nothing about what am actually doing wrong:

VM15235:27 Warning: React.createElement: type should not be null, undefined, boolean, or number. It should be a string (for DOM elements) or a ReactClass (for composite components). Check the render method of `Header

and:

invariant.js:38 Uncaught (in promise) Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. Check the render method of `Header`.(…)

Is there a way of making this more explicit?


回答1:


There was a change to material-ui that renamed LeftNav to Drawer! It seems like certain docs/examples haven't been updated. So if you use Drawer you will find documentation and it should work! Here is the commit/thread from the change away from LeftNav.

https://github.com/callemall/material-ui/issues/2697



来源:https://stackoverflow.com/questions/37119207/unable-to-implement-leftnav-with-appbar-component-in-material-ui

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