React Native随笔——警告处理方法(持续更新)

一、警告propTypes was defined as an instance property on commonTabar. Use a static property to define propTypes instead.

警告如下图:

1、解决方法

原来的如下图一,修改后的如下图二。把propTypes放置到class类的外边,reload后警告就不见了。

2、原因

出现上面问题的原因是,在es6版本中,对一些语法进行了更改,更改的内容中都有以下属性的修改: 
将propTypes、getDefaultTypes等类属性移到类外面定义,由于ES6类中只允许定义方法并不允许定义类属性,所以像原先会在 createClass 中定义的 propTypes 、 getDefaultTypes 、 displayName 还有 contextTypes 等组件属性都要放到类外面来赋值。

 

二、警告each child in an array or iterator should have a unique ‘key’ prop

警告如下图:

 

1、解决方法

原来的如下图一,修改后的如下图二。图一中没有key,图二在子项添加一个key就好了。

2、 原因

react native循环遍历时需要一个唯一的key。

下面这段是从知乎看到的:

这个是和react的dom-diff算法相关的。react对dom做遍历的时候,会根据data-reactid生成虚拟dom树。如果你没有手动的添加unique constant key的话,react是无法记录你的dom操作的。它只会在重新渲染的时候,继续使用相应dom数组的序数号(就是array[index]这种)来比对dom树。
 

三、Android安装APK报错:Installation error: INSTALL_FAILED_UPDATE_INCOMPATIBLE

1、解决方法

adb uninstall 包名(例如com.ginger.happy)

2、 原因

原来的包没有卸载干净(我的小米总是卸载不干净,华为就没有这个问题)

 

四、报错Undefined is not an object(evaluating ‘_react2.PropTypes.func’)

报错如下图:

1、解决方法

把原来的写法

import React, { Component, PropTypes } from 'react';

改为

import React, {Component} from 'react';
import PropTypes from 'prop-types';

2、原因  

应该是版本更新问题,之前用0.44时这样写是没有问题的,刚新建的项目是0.52的,出现了这个报错。

 

-----------2019.06.05更新--------------

五、react-native run-android时报错Could not resolve all files for configuration ':app:debugRuntimeClasspath'

报错如下图:

解决方法:

打开android -> build.gradle

将如下代码

allprojects {
    repositories {
        jcenter()
        ………
        ………
    }
}        

改为

allprojects {
    repositories {
        jcenter { url "http://jcenter.bintray.com/"}
        ………
        ………
    }
}   

 

 -----------2019.07.10更新--------------

六、报错Unable to find module for EventDispatcher

报错如下图:

解决方法:

先Stop remote JS debugging,然后reload,就可以看到具体错误,然后根据错误提示进行解决。

 

END --------------------------------------------------

 

posted @ 2017-10-25 11:22  麦豇豆  阅读(2114)  评论(0编辑  收藏  举报