Javascript Reactjs:警告:React.createElement:类型不应为空或未定义
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31791887/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Reactjs: Warning: React.createElement: type should not be null or undefined
提问by Non
this the full error
这是完整的错误
Warning: React.createElement: type should not be null or undefined. It should be a string (for DOM elements) or a ReactClass (for composite components).
警告:React.createElement:类型不应为空或未定义。它应该是一个字符串(对于 DOM 元素)或一个 ReactClass(对于复合组件)。
and this is all I have in this view
这就是我在这个观点中的全部
import React, { Component } from 'react';
import Router, {Link, RouteHandler} from 'react-router';
import { Grid, Row, Column, List, ListItem } from '../../components/Layout';
import { RaisedButton, Paper } from 'material-ui';
const videosInformation = {
time : 25,
gameId : 15665,
date : '12 10 2015',
gameName : "Black Hyman"
};
export default class Home extends Component {
static contextTypes = {
router : React.PropTypes.func
}
render () {
return <Grid>
<Row>
<Column>
<Paper>
<List subheader="Player Info">
<ListItem primaryText={`Name: ${videosInformation.time}`} />
<ListItem primaryText={`Nickname: ${videosInformation.date}`} />
<ListItem primaryText={`Age: ${videosInformation.gameId}`} />
<ListItem primaryText={`Language: ${videosInformation.gameName}`} />
</List>
</Paper>
</Column>
<Column>
<iframe width="560" height="315" src="https://www.youtube.com/embed/Ta4xuThmAsQ" frameBorder="0" allowFullScreen></iframe>
</Column>
</Row>
</Grid>;
};
}
I am using Material-UI
我正在使用Material-UI
采纳答案by Ed Ballot
It is likely that your Layout
file is not exporting one of the variables from this line
您的Layout
文件很可能没有从这一行导出变量之一
import { Grid, Row, Column, List, ListItem } from '../../components/Layout';
The warning would happen if one of those is undefined.
如果其中之一未定义,则会发生警告。
回答by pjehan
I know the right solution has been found here but I just wanted to share another possible reason for the ReactJS React.createElement: type should not be null or undefined
warning to trigger.
我知道在这里找到了正确的解决方案,但我只是想分享React.createElement: type should not be null or undefined
触发ReactJS警告的另一个可能原因。
It can also happens when you have a circular dependency in your modules. Then, doing a console.log()
of your imported module would return an empty object.
当您的模块中有循环依赖时,也会发生这种情况。然后,执行console.log()
导入模块的操作将返回一个空对象。
For further details, have a look at this other stackoverflow thread: Require returns an empty object
有关更多详细信息,请查看另一个 stackoverflow 线程:Require returns an empty object
回答by Michael McAlpin
Just in case anyone has run into this issue and the above solutions are not helping, all I had to do was move my top-level ReactDOM.render() function below the rest of the JavaScript to ensure all variables were initialized before being called. I was following the tutorial at https://reactjs.net/getting-started/tutorial_aspnet4.html
以防万一有人遇到这个问题并且上述解决方案没有帮助,我所要做的就是将我的顶级 ReactDOM.render() 函数移到 JavaScript 的其余部分下方,以确保所有变量在调用之前都已初始化。我正在关注https://reactjs.net/getting-started/tutorial_aspnet4.html 上的教程