ES6 + React,错误:React.createElement:type不应为null,undefined,boolean或number(ES6+React, Error:React.createElement: type should not be null, undefined, boolean, or number)
用ES6学习ReactJS。 尝试实现React-Bootstrap组件。 我也在使用react路由器。 我正在尝试实现Navbar组件。
它只是一个品牌和搜索框的nabber。 我的目标是扩展和使用搜索框组件,所以我将它放在下面的独立组件中。
LocationSearchBox.js
import React, {PropTypes} from 'react' import Form, {FormGroup, FormControl} from 'react-bootstrap' export default function LocationSearchBox(props) { return ( <FormGroup> <FormControl type="text" placeholder="Search" /> <Button bsStyle="success" type="submit">Submit</Button> </FormGroup> ) }
导航器将位于所有页面上,因此我将其放在最顶层的路径中,其组件是下面显示的Main.js文件以及用于管理客户端路由的routes.js。
import React, {Component} from 'react'; import {Navbar, NavbarHeader, NavbarBrand, NavbarCollapse} from 'react-bootstrap'; import {default as Search} from './LocationSearchBox' export default class Main extends Component{ constructor(props) { super(props); this.props = props; } render() { return( <Navbar> <NavbarHeader> <NavbarBrand> <a href="#">React-Bootstrap</a> </NavbarBrand> </NavbarHeader> <NavbarCollapse> <Search/> </NavbarCollapse> </Navbar> ) } }
routes.js
import React from 'react'; import ReactRouter, {Router, Route, IndexRoute, browserHistory} from 'react-router'; import Main from '../components/Main'; export var routes = ( <Router history={browserHistory}> <Route path='/' component={Main} /> </Router> );
Index.js在下面,是Webpack / babel中使用的入口文件
import React from 'react'; import ReactDOM from 'react-dom'; import {routes} from './config/routes'; ReactDOM.render(routes, document.getElementById('root'));
因此,当我运行web pack-dev-server时,请转到localhost:8080作为主路由应该命中的默认端口。 我相信它确实如此,但我得到了错误,即3个同类错误。
Warning: 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 `Main`.
我相信这可能是由于我在Main.js中导入Navbar组件的方式,例如NavbarHeader,NavbarCollapse等,但这是猜测。 我非常感谢你解决这个问题的任何帮助,谢谢。
Learning ReactJS with ES6. Trying to implement React-Bootstrap components. I am also using the react router. I am trying to implement the Navbar component.
It will just be a nabber with the brand and a search box. I aim to expand and use the search box component a lot more so I have put it in its own separate component below.
LocationSearchBox.js
import React, {PropTypes} from 'react' import Form, {FormGroup, FormControl} from 'react-bootstrap' export default function LocationSearchBox(props) { return ( <FormGroup> <FormControl type="text" placeholder="Search" /> <Button bsStyle="success" type="submit">Submit</Button> </FormGroup> ) }
The navber will be on all pages so I have put it in the topmost route and its component is the Main.js file shown below along with routes.js to manage client side routes.
import React, {Component} from 'react'; import {Navbar, NavbarHeader, NavbarBrand, NavbarCollapse} from 'react-bootstrap'; import {default as Search} from './LocationSearchBox' export default class Main extends Component{ constructor(props) { super(props); this.props = props; } render() { return( <Navbar> <NavbarHeader> <NavbarBrand> <a href="#">React-Bootstrap</a> </NavbarBrand> </NavbarHeader> <NavbarCollapse> <Search/> </NavbarCollapse> </Navbar> ) } }
routes.js
import React from 'react'; import ReactRouter, {Router, Route, IndexRoute, browserHistory} from 'react-router'; import Main from '../components/Main'; export var routes = ( <Router history={browserHistory}> <Route path='/' component={Main} /> </Router> );
Index.js is below and is the entry file to use in Webpack/babel
import React from 'react'; import ReactDOM from 'react-dom'; import {routes} from './config/routes'; ReactDOM.render(routes, document.getElementById('root'));
So when i run web pack-dev-server, go to localhost:8080 as the default port the main route should be hitting. I believe it does but I get errors, namely 3 of the same kind.
Warning: 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 `Main`.
I believe it might be due to the way I am importing the Navbar components in Main.js, such as NavbarHeader, NavbarCollapse etc but that is a guess. I would really appreciate any help in solving this issue, thank you.
原文:https://stackoverflow.com/questions/38807169
最满意答案
您似乎正在为模拟器构建,这与i386架构相对应,但您只能与iphone(arm)库链接。
要解决这个问题,您应该为i386和arm编译库libICodeMathUtils.a。
在查看了您所遵循的教程之后:在项目中集成静态库的更好方法是定义依赖项。 你可以看看Xcode 4的这篇SO文章,以及Xcode 3的这篇文章(问题本身给出了步骤)。
另一个选择是为i386(模拟器)和arm(设备)单独构建库,然后使用命令行工具
lipo
创建一个可以在MathTest项目中链接的胖库。 检查man lipo
以了解hoy使用该工具。编辑:关于你的评论
我的静态库没有在Target Dependencies中显示!!
您是否已将静态库从包含的项目树拖到目标? Xcode 3的步骤是:
将库项目添加为包含项目;
在包含的项目中找到静态库并将其拖到主目标上,将其添加为链接框架;
最后,在目标信息窗格中,您可以添加依赖项。
如果将目标添加到项目Scheme中,Xcode4似乎能够自动计算出依赖关系。 您可以通过执行以下操作来执行此操作:编辑方案 - >构建 - >,然后从工作区添加目标。 另见这个问题 。
You are seemingly building for the simulator, which corresponds to the i386 architecture, but you are only linking with an iphone (arm) library.
To solve this, you should compile your library libICodeMathUtils.a both for i386 and arm.
After lookng at the tutorial you followed: a better way of integrating a static library in your project is by defining a dependency. You can look at this S.O. article for Xcode 4, and to this one for Xcode 3 (steps are given in the question itself).
Another option you have is building your library separately for i386 (simulator) and arm (device) and then use the command line tool
lipo
to make a fat library that you can link in your MathTest project. Checkman lipo
to know hoy to use the tool.EDIT: about your comment
My static library does not show in Target Dependencies !!
have you dragged the static library from the included project tree to the target? the steps for Xcode 3 are:
add the library project as an included project;
find the static library in the included project and drag it on to your main target, adding it as a linked framework;
finally, in your target info pane, you can add the dependency.
Xcode4 seems to be able to automatically figure out dependencies, provided the targets are added to the project Scheme. You can do so by executing: Edit Scheme -> Build -> and then adding targets from your workspace. See also this S.O. question.