TypeError: null is not an object (evaluating 'children.push') SvgUri

问题描述

react-native-svg 库的 SvgUri 模块工作正常,因为它通过 uri 呈现图标,但几秒钟后使用它会引发如下错误

“类型错误:null 不是对象(评估 'children.push')” 或者: “无法读取 null 的属性 'push' 此错误位于:在 SvgUri 中”

这几乎是同样的错误

如何修复错误

注意:SvgUri 用于 FlatList 的项目

解决方法

我有同样的错误。原来我不小心在 url 字符串中有一个尾随空格。

const resourceUrl = 'https://example.com/filename.svg ' // <- naughty space

<SvgUri
  uri={resourceUrl}
/>