美文网首页
React-Native 踩坑

React-Native 踩坑

作者: 简简单就好 | 来源:发表于2018-06-26 23:15 被阅读0次

    1.错误日志:Warning: Failed child context type: Invalid child context virtualizedCell.cellKey of type number supplied to CellRenderer, expected string

    原因:使用FlatList出现的红色错误警告,原因是FlatList的每一个Item都需要一个唯一的key来标记识别,并且此标记的value值可接受类型是string
    处理方法:将keyExtractor此值转换为string
    处理代码:
    <FlatList
             data={this.state.dataList}
             renderItem={this.renderCell}
             keyExtractor={this.keyExtractor}
             onRefresh={this.requestData}
             refreshing={this.state.refreshing}
             ListHeaderComponent={this.renderHeader}
     />
    
    keyExtractor = (item: Object, index: number) => {
            return item.id.toString()
    }
    
    2.错误:React-Navigation使用出现Warning: isMounted(...) is deprecated in plain Javascript Classes. Inst
    原因:源代码内部有被React放弃维护弃用的方法
    处理方法:在index.js中引入以下代码,忽略警告
    处理代码:
    import { YellowBox } from 'react-native';
    YellowBox.ignoreWarnings(['Warning: isMounted(...) is deprecated', 'Module RCTImageLoader']);
    

    相关文章

      网友评论

          本文标题:React-Native 踩坑

          本文链接:https://www.haomeiwen.com/subject/hpymyftx.html