Failure to call AppRegistry.registerComponent
1、首先确认你的index.ios.js文件中,有注册方法:AppRegistry.registerComponent('FacebookTabsExample', () => FacebookTabsExample);
2、确定你的Appdelegate.m文件中,获取到正确的index.ios. js文件
3、如果上述条件都满足,那么,确认一下在此之前你是不是用终端运行过另一个RN项目(react-native run-ios)有的话,把终端的运行服务关闭。关闭完之后,重新运行你要运行的项目。
Element type is invalid: expected a string (for building-in components) or a class/function (for composite components) but got: object Check the render method of 'XXXX'.
分析:这个错误的原因是ES5和ES6语法混乱搭配导致的。
将导入语法形式由:
var React = require('react-native');
var WeatherProject = require('./WeatherProject')
改成:
import React from 'react-native';
import WeatherProject from './WeatherProject';
将导出语法形式由:
module.exports = WeatherPro;
改为:
export default class WeatherPro extends Component {
null is not an object(evaluating 'this.state.XXX')
状态state初始化失败,将初始化方式从getInitialState,在ES6中,初始化需要把初始化的对象放在Constructor方法中,而不是getInitial..
将原先格式:
getInitialState() {
return({
zip:'' }); }
改成:
constructor(props){
super(props);
this.state = {
zip:'' }; }
this.setState is not a function
在react中的this作为的是组件的实例,当成功回调的时候,就改变了this的指向;react中支持箭头(=>)指向this,和bind()函数绑定组件实例
将原先格式:
onSubmitEditing = {this._handleTextChange}
改成:
onSubmitEditing = {() => this._handleTextChange()}