首页 > 解决方案 > 为什么 redux 商店的对象属性值来自 firestore '9' 而不是 img url?

问题描述

当在我的 react-native 应用程序中加载屏幕时,我使用来自 redux 存储的 url,由 firestore 读取操作(存储在 firebase-storage 中的图像)填充作为图像组件的源。如果我像这样创建图像的源道具source={{ui:this.props.someURL}},我会得到

TypeError: NSNull cannot be converted to NSString

好的,我知道这是关于图像源道具的已知问题。我尝试使用以下方法修复它:

source={{ 
  uri: this.props.profileImg == null ?
  require('../assets/img/white-user.png') : 
  this.props.profileImg
}}

然后我从问题标题中得到错误: JSON value '9' of type NSNumber cannot be converted to NSString 如果我完全删除有问题的图像组件,则没有错误。

this.props.someURL内部构造函数的记录值=null

this.props.someURLinside componentDidMount()= null的记录值

正如预期的那样,因为这些值是由承诺填充的。那么为什么会JSON value of '9'出错呢?这仅在 iOS 中

标签: react-nativereact-reduxfirebase-storagereact-native-ios

解决方案


你可以替换你的源道具

source={{ 
    uri: this.props.profileImg == null ?
    require('../assets/img/white-user.png') : 
    this.props.profileImg
}}

source={
    this.props.profileImg == null ?
    require('../assets/img/white-user.png') : {
        uri:this.props.profileImg
    } 
}

推荐阅读