React Native 问题总结
2017-08-29 本文已影响0人
TonyReet
最近开始学习ReactNative,遇到了一些坑,总结一下方便以后查找。
1、react.children.only expected to receive a single react element child
TabNavigator.Item的时候出现了如上的错误,TabNavigator.Item必须包含一个子组件(不能超过也不能没有),报错之前代码如下:
<TabNavigator.Item
title="xxxxx"
renderIcon={() => <Image source={{uri: 'yyyyy'}} style={styles.iconStyle}/>}
renderSelectedIcon={() =><Image source={{uri: 'zzzzz'}} style={styles.iconStyle}/>}
>
</TabNavigator.Item>
此时会报错,添加子组件即可:
<TabNavigator.Item
title="xxxxx"
renderIcon={() => <Image source={{uri: 'yyyyy'}} style={styles.iconStyle}/>}
renderSelectedIcon={() =><Image source={{uri: 'zzzzz'}} style={styles.iconStyle}/>}
>
<View >
<Text>xxxx</Text>
</View >
TabNavigator.Item>
2、Navigator is deprecated and has been removed from this package. It can now be installed and imported from react-native-deprecated-custom-components
从0.44版本开始,Navigator不再从‘react-native’中引入
解决办法:
1、使用终端打开对应的目录 cd 路径
2、
npm i react-native-deprecated-custom-components --save
3、在对应的文件种将组件引入
import {Navigator} from 'react-native-deprecated-custom-components';