react-native - 为什么 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.someURL
inside componentDidMount()
= null的记录值
正如预期的那样,因为这些值是由承诺填充的。那么为什么会JSON value of '9'
出错呢?这仅在 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
}
}
推荐阅读
- pyqt5 - PyQt5 获取具有多个值的输入
- puppeteer - 如何记录发送到 Puppeteer/Chrome 开发者的每个事件
- math - 使用 DrRacket(方案)在偶数个垫子上跳蛙
- azure - 如何将 Azure 测试计划与管道相结合?
- visual-studio - 如何使用 WSL 从 Bash 构建现有的仅限 Windows 的 Visual Studio 项目
- python - Python脚本调用api并返回json输出
- c# - pt-BR 的 Bot Framework Emulator 语言环境问题
- terminal - Iterm2 首选项:显示带有目录、日期和 git 的栏
- java - 一次不能发出一件物品,每次我发出一件物品时,它总是发出所有剩下的物品,而不是只发出一件物品
- mysql - Kubernetes mariadb 用户登录