首页 \ 问答 \ ES6 + React,错误:React.createElement:type不应为null,undefined,boolean或number(ES6+React, Error:React.createElement: type should not be null, undefined, boolean, or number)

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
更新时间:2023-09-18 21:09

最满意答案

您似乎正在为模拟器构建,这与i386架构相对应,但您只能与iphone(arm)库链接。

要解决这个问题,您应该为i386和arm编译库libICodeMathUtils.a。

在查看了您所遵循的教程之后:在项目中集成静态库的更好方法是定义依赖项。 你可以看看Xcode 4的这篇SO文章,以及Xcode 3的这篇文章(问题本身给出了步骤)。

另一个选择是为i386(模拟器)和arm(设备)单独构建库,然后使用命令行工具lipo创建一个可以在MathTest项目中链接的胖库。 检查man lipo以了解hoy使用该工具。

编辑:关于你的评论

我的静态库没有在Target Dependencies中显示!!

您是否已将静态库从包含的项目树拖到目标? Xcode 3的步骤是:

  1. 将库项目添加为包含项目;

  2. 在包含的项目中找到静态库并将其拖到主目标上,将其添加为链接框架;

  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. Check man 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:

  1. add the library project as an included project;

  2. find the static library in the included project and drag it on to your main target, adding it as a linked framework;

  3. 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.

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)