简体   繁体   English

Reactjs未捕获的错误:元素类型无效:预期为字符串

[英]Reactjs Uncaught error: Element type is invalid: expected a string

I get the following error: 我收到以下错误:

"Uncaught 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 App " “未捕获的错误:元素类型无效:预期为字符串(对于内置组件)或类/函数(对于复合组件),但得到:未定义。请检查App的渲染方法”

I have checked and doubled checked my code and I cannot workout the problem. 我已经检查并仔细检查了我的代码,但无法解决问题。

Anyone know why? 有人知道为什么吗? See code below. 请参见下面的代码。

App.js App.js

import React, {Component} from 'react';
import ReactDOM from 'react-dom';
//import ReactD3, {BarChart, LineChart} from 'react-d3-components';
import {MenuList} from './menu/menulist.js';
import {TabList} from './menu/tablist.js';
import {TabContainer, TabContent, TabPane, Nav, Tab, Row, Col} from 'react-bootstrap';

class App extends Component{
  constructor(props){
    super(props);
  }
  render(){
    console.log("Here 1")
    const menunames = [
      {id: "first", name: "Tab 1"},
      {id: "second", name: "Tab 2"}
    ];

    const plist = [
      {id: "first", name: "Content 1"},
      {id: "second", name: "Content 2"}
    ];
    console.log("Here 2")
    return (
       <div className="app">
        <Tab.Container id="left-tabs-example">
        <Row className="clearfix">
          <Col sm={4}>
            <MenuList items={menunames} />
          </Col>
          <Col sm={8}>
              <TabList panels={plist} />
          </Col>
        </Row>
      </Tab.Container>
     </div>
   );
  }
}

export default App

menulist.js menulist.js

import React, {Component} from 'react';
import ReactDOM from 'react-dom';
import {TabContainer, TabContent, TabPane, Nav, NavItem, Tab, Row, Col} from 'react-bootstrap';

class MenuList extends Component{
  constructor(props){
    super(props);
  }

  MenuItem({ menuitems }){
    return menuitems.map(item => (
      <NavItem eventKey={item.id}>
        {item.name}
      </NavItem>
    ))
  }

  render(){
    return (
      <Nav bsStyle="pills" stacked>
        <MenuItem menuitems={this.props.items} />
      </Nav>
    )
  }
}

MenuList.propTypes = {
  items: React.PropTypes.array
}

export default MenuList

tablist.js tablist.js

import React, {Component} from 'react';
import ReactDOM from 'react-dom';
import {TabContainer, TabContent, TabPane, Nav, Tab, Row, Col} from 'react-bootstrap';

class TabList extends Component{
  constructor(props){
    super(props);
  }

  TabPanel({ pans }){
    return pans.map(panel => (
      <Tab.Pane eventKey={panel.id}>
        {panel.name}
      </Tab.Pane>
    ))
  }

  render(){
    return (
      <Tab.Content animation>
        this.props.panels.map(panel => (
          <Tab.Pane eventKey={panel.id}>
            {panel.name}
            </Tab.Pane>
          )
      </Tab.Content>
    )
  }
}

TabList.propTypes = {
  panels: React.PropTypes.array
}

export default TabList
import {MenuList} from './menu/menulist.js'; // not correct
import {TabList} from './menu/tablist.js';

If You have export default You don't need curly bracers in import . 如果您具有export default则在import不需要花括号。

import MenuList from './menu/menulist.js'; //correct
import TabList from './menu/tablist.js';


Export {MyComponent, MySecondComponent};  -> import {MyComponent, MySecondComponent} from './path';
Export default MyComponent -> import MyComponent from './path';

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 未捕获的错误:元素类型无效:应为字符串 - Uncaught Error: Element type is invalid: expected a string 未捕获的错误:元素类型无效:应为字符串 - Uncaught Error: Element type is invalid: expected a string 未捕获的错误:不变违规:元素类型无效:应为字符串 - Uncaught Error: Invariant Violation: Element type is invalid: expected a string 错误:元素类型无效:需要一个字符串(对于内置组件)-reactjs - Error: Element type is invalid: expected a string (for built-in components) - reactjs 未捕获的错误:元素类型无效:预期为字符串(内置组件)或类/函数(复合组件),但得到:未定义 - Uncaught Error: Element type is invalid: expected a string (built-in components) or a class/function ( composite components) but got: undefined 未捕获的错误:元素类型无效:预期为字符串(对于内置组件)或类/函数(对于复合组件)但得到:未定义 - Uncaught Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got:undefined 未捕获的错误:元素类型无效:需要一个字符串(对于内置组件)或一个类/函数但得到:对象 - Uncaught Error: Element type is invalid: expected a string (for built-in components) or a class/function but got: object 未捕获的错误:始终违反:元素类型无效:预期为字符串或类/函数,但得到:对象 - Uncaught Error: Invariant Violation: Element type is invalid: expected a string or a class/function but got: object React Memo功能给出: - 未捕获的错误:元素类型无效:期望一个字符串但得到:object - React Memo Feature gives :- Uncaught Error: Element type is invalid: expected a string but got: object 未捕获的错误:不变违规:元素类型无效:需要一个字符串(对于内置组件)或一个类/函数但得到:object - Uncaught Error: Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function but got: object
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM