TypeError:在createElement上未定义React对象

时间:2016-11-15 01:48:29

标签: javascript reactjs tabs material-ui appbar

我是ReactMaterial UI的新手,我正在尝试使用AppBar作为孩子创建Tabs。我目前的实现如下:

import {React, PropTypes, Component} from 'react';
import TodoTextInput from './TodoTextInput';
import injectTapEventPlugin from 'react-tap-event-plugin';
import baseTheme from 'material-ui/styles/baseThemes/lightBaseTheme'
import getMuiTheme from 'material-ui/styles/getMuiTheme'
import {Tabs, Tab} from 'material-ui/Tabs';
import {AppBar} from 'material-ui/AppBar';

const styles = {
  headline: {
    fontSize: 24,
    paddingTop: 16,
    marginBottom: 12,
    fontWeight: 400
  }
};

function handleActive(tab) {
  alert(`A tab with this route property ${tab.props['data-route']} was activated.`);
}
const defaultStyle = {
  marginLeft: 20
};

class Header extends Component {
  render() {
    return (
      <header className="header">
      <AppBar title="TEST" />
        <Tabs>
          <Tab label="Tab 1" >
            <div>

            </div>
          </Tab>
          <Tab label="Tab 2" >
            <div>

            </div>
          </Tab>
          <Tab label="Tab 3" >
            <div>

            </div>
          </Tab>
          <Tab label="Tab 4" >
            <div>

            </div>
          </Tab>
        </Tabs>
        {children}
      </header>
    );
  }
}

module.exports = Header;

我收到一条错误消息:

TypeError: undefined is not an object (evaluating '_react.React.createElement')

我不确定如何解决这个问题。请帮忙!

3 个答案:

答案 0 :(得分:8)

您导入的React错误,但您已经关闭了。将其更改为

import React, { PropTypes, Component } from 'react';

将React视为父母,将其他人视为孩子。您也可以导入React并使用React.PropTypesReact.Component访问另一个。

答案 1 :(得分:1)

我遇到错误:“ React.createElement不是函数”,对于我来说,解决方法是更改​​此错误:

import React from "react-native";

收件人

import React from "react";

谢谢,我通过将导入React从“ react-native” 更改为导入React从“ react” 来解决此问题。

答案 2 :(得分:0)

我也遇到了同样的问题。这解决了它:

import React,{useState} from 'react'; //Right 
import {React,useState} from 'react-native'; //Wrong