我是React
和Material 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')
我不确定如何解决这个问题。请帮忙!
答案 0 :(得分:8)
您导入的React错误,但您已经关闭了。将其更改为
import React, { PropTypes, Component } from 'react';
将React视为父母,将其他人视为孩子。您也可以导入React并使用React.PropTypes
和React.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