我尝试将项目拆分为多个文件,当我尝试导入文件时,我收到此警告/错误
warning.js:36Warning: React.createElement: type should not be null, undefined, boolean, or number. It should be a string (for DOM elements) or a ReactClass (for composite components). Check the render method of
{菜单{1}} {菜单{1}} {菜单{1}}
我试过谷歌搜索这个问题,我看到很多这样的帖子,但我无法解决这个问题。 这是Menu.jsx
.
warning.js:36Warning: React.createElement: type should not be null, undefined, boolean, or number. It should be a string (for DOM elements) or a ReactClass (for composite components). Check the render method of
这里是app.jsx
.
invariant.js:38 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
好吧,我尝试了几乎所有我从搜索中找到的东西,不知道我在这里丢失了什么...但我真的很困惑这些错误。
我真的很喜欢React。
如果我将Menu类放在app.jsx中并将其定义为其他类,那么我会注意到它会正常工作。
编辑:我使用webpack编译反应文件。
谢谢!
答案 0 :(得分:0)
To me looks like the problem is with the Link
import from react-router
in the Menu.jsx
file. It should be like this:
import { Link } from 'react-router'
export default class Menu extends Component {
Please note the {}
. React router exports an object with a Link key.
In the second file your import looks fine:
import { Router, Route, Link, browserHistory } from 'react-router'
That explains why this worked when you pasted the Menu class in there.
A hint here is the error message:
Check the render method of Menu.
So you can be sure that the Menu class is being loaded, and the error is in your render function. If the Menu file wasn't found you would get a message saying that Menu is undefined or something like that.