Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError : React object is undefined on createElement

I am new to React and Material UI and I am attempting to create an AppBar with Tabs as children. My current implementation looks like this:

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;

I'm getting an error that states:

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

I am unsure on how to fix this problem. Please help!

like image 956
Brig Avatar asked Nov 15 '16 01:11

Brig


3 Answers

You are importing React wrong, you're close though. Change it to

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

Think of React as the parent and the others as children. You could also just import React and access the other with React.PropTypes and React.Component.

like image 119
Andrew Axton Avatar answered Nov 10 '22 23:11

Andrew Axton


I was getting error: "React.createElement is not a function" and for my situation the fix was to change this:

import React from "react-native";

To

import React from "react";

Thanks, I fixed this by changing import React from 'react-native' to import React from 'react'.

like image 27
Akshita Agarwal Avatar answered Nov 10 '22 22:11

Akshita Agarwal


I was also facing same issue. This solves it:

import React,{useState} from 'react'; //Right 
import {React,useState} from 'react-native'; //Wrong
like image 1
user12426087 Avatar answered Nov 11 '22 00:11

user12426087