ReactNative使用错误汇总

2018-01-04  本文已影响0人  HermitCarb

1. Raw text cannot be used outside of a <Text> tag. Not rendering string: ''

比较明显,说渲染空字符串''必须放到<Text>标签里,可是怎么会犯这么低级的错误呢?而且调用栈也没有给出了出错的正切的位置。

ExceptionsManager.js:73 Raw text cannot be used outside of a
    <Text> tag. Not rendering string: ''
    reactConsoleErrorHandler    @   ExceptionsManager.js:73
    console.error   @   YellowBox.js:71
    logToConsole    @   RCTLog.js:48
    logIfNoNativeHook   @   RCTLog.js:31
    __callFunction  @   MessageQueue.js:302
    (anonymous) @   MessageQueue.js:116
    __guard @   MessageQueue.js:265
    callFunctionReturnFlushedQueue  @   MessageQueue.js:115
    (anonymous) @   debuggerWorker.js:72

经过半个钟头的暴力排查,发现出问题的位置:

{
  props.title && (
    <Text style={[styles.btnTtile, props.titleStyle]} numberOfLines={1}>
      {props.title}
    </Text>
  )
}

原来是判定表达式值的原因,上述表达式中props.title的值为nullundefined都没有问题,因为nullundefined都不是String类型,直接渲染是没有问题的,不会有什么影响,但是字符串''渲染必须是放到Text中。
修改如下:

{
  props.title ? (
    <Text style={[styles.btnTtile, props.titleStyle]} numberOfLines={1}>
      {props.title}
    </Text>
  ) : (null)
}

2.使用某个依赖库出现一些看不懂的错误,解决又无从下手时。

可以查看一下该依赖库的package.json文件,看看其中的dependenciesdevDependenciespeerDependencies中的依赖项是否和自己项目中的依赖项版本匹配,如果不匹配请尝试更新/回退依赖项目中不匹配的依赖项,或者更新/回退上面出问题的依赖库。

注:不保证一定有用。

3.本地png图片无法显示,其他图片正常

可能是这几个图片是16bits的,尝试转换成8bits的试试。
我用的mac,操作如下:

  1. 在Finder中打开图片,然后复制另存图片
  2. 复制:Command + Shift + S
  3. 保存:Command + S
  4. 选择8bits保存

好像没办法上传gif,这里有张图:https://pic3.zhimg.com/50/v2-2856704e140b1bb765fb903eb1cd8f6b_hd.gif

上一篇下一篇

猜你喜欢

热点阅读