React Native 错误收集(持续 )

最近开始使用学习 React Native,再次记录所遇到的错误

  1. Cannot add a child that doesn't have a YogaNode to a parent without a measure function! (Trying to add a 'ReactRawTextShadowNode' to a 'LayoutShadowNode')

代码如下

App.js
export default class App extends Component<{}> {
render() {
      if (Platform.OS === 'android') {
        return <ViewTest style={{flex:1}}/>
      }
  }
}
// ViewTest.js
export default class ViewTest extends Component{
render(){
    return (
        <View style={[styles.container,styles.flex]}>
            <View style={styles.item}>
                // 第1列
                <View style={[styles.flex,styles.center]}>
                    <Text style={styles.textStyle}>酒店</Text>
                </View>
            </View>
        </View>
    )
};
}
复制代码

问题原因及解决方案: // 这不是 ReactNative 在 JSX 中的注释方式,注释方式为 {/**/},更改注释后就好了。

  1. Navigator 使用错误。 这两天在使用 Navigator 时一直报错。 错误一:
Invariant Violation: Navigator is deprecated and has been removed from this package. 
It can now be installed and imported from `react-native-deprecated-custom-components` instead of `react-native`. 
Learn about alternative navigation solutions at http://facebook.github.io/react-native/docs/navigation.html
复制代码

错误原因及解决方案: 错误原因是因为 React Native 在 0.44 以后已经把 Navigator 废弃掉了,不能使用 import {Navigator} from 'react-native'; 进行导入了。根据提示需要导入 react-native-deprecated-custom-components 解决步骤: 1.进入到项目的根目录下。 2.使用命令行 :npm install react-native-deprecated-custom-components --save 3.在使用Navigator的地方引用。引用方式:import {Navigator} from "react-native-deprecated-custom-components" 注意:在引用时 一定在导入 Navigator的时候加上 {} 要不然会报错。

安装如果出错的解决: 方案一:使用命令:npm i react-native-deprecated-custom-components --save 如果此方法还不能解决。 方案二:使用yarn命令(前提是自己有yarn的配置环境)yarn add react-native-deprecated-custom-components --save

Navigator 错误二: 我在上述引用 react-native-deprecated-custom-components 后,使用 Navigator 还是会报错。 错误提示: Cannot read property 'shape' of undefined

错误还是因为 React Native 在 0.44 以后已经把 Navigator 废弃掉了。 现在要改为用 React Navigation。详情请参考github react-nativeReact Native 使用文档新手理解Navigator的教程 PS : 这个错误卡了我两天啊。。。

3.PropTypes 错误 Cannot read property 'string' of undefined

错误原因:使用 PropTypes 时导入出错。 import React, {Component,PropTypes} from 'react'; 原因是 : React v15.5 起就被移除了,需要改用 prop-types 库代替。 解决方案:

  1. 进入项目根目录,安装 prop-types 库:npm install --save prop-types
  2. 引入:import PropTypes from 'prop-types';
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值