Error RawText ** must be wrapped in an explicit <Text> component 问题解决
来源:互联网 发布:手机上网数据自动关闭 编辑:程序博客网 时间:2024/06/10 06:41
今天忽然遇到一个页面崩溃,查到错误如下:
Error: RawText "" must be wrapped in an explicit <Text> component.
查了代码,发现好久都没有动这块的代码了,所以非常疑惑。最后通过2分法不停地查哪里出了问题,最终查到了这个语句:
return ( <View> {test && test.string && <Text>{test.string}</Text> } </View>)
其实作用很简单,如果string有值,则展示string。但是这条语句为什么会报错呢?查了半天,发现是因为string的值是”,然后系统就报错了,类似这样:
let test = {string: ''};return ( <View> {test && test.string && <Text>{test.string}</Text> } </View>)
后来查了下github,发现很多人也遇到了类似的错误,解决办法如下,使用!!来判断string是否有值,因为这里其实你是希望将string
当成bool
来使用的。
let test = {string: ''};return ( <View> {test && !!test.string && <Text>{test.string}</Text> } </View>)
所以以后string的判断,都用!!去判断,否则出现string恰好为”的时候,就会崩溃。
参考文章:
- https://github.com/GeekyAnts/NativeBase/issues/186
阅读全文
0 0
- Error RawText ** must be wrapped in an explicit <Text> component 问题解决
- RawText "123" must be wrapped in an explicit <Text> component
- RawText "/*" must be wrapped in an explicit <Text> component
- RawTest '1' must be wrapped in an explicit <Text> component
- React Native error: Raw “ ” must be wrapped in an explicit <Text> Component
- Adjacent JSX elements must be wrapped in an enclosing tag
- Adjacent JSX elements must be wrapped in an enclosing tag
- react+babel2+fis3实现jsx报错Adjacent JSX elements must be wrapped in an enclosing tag (10:0)
- Magento: Recoverable Error: Argument 1 passed to Mage_Core_Model_Store :: setWebsite() must be an in
- An SDK Target must be specified.” 问题解决(转载)
- 解决ServiceIntent must be explicit
- Service Intent must be explicit
- Service Intent must be explicit
- Service Intent must be explicit
- Error:Execution failed for task ':app:javaPreCompileDebug'. > Annotation processors must be explicit
- Error:Execution failed for task ':app:javaPreCompileDebug'. > Annotation processors must be explicit
- error : A file found in a source-path must have an externally visible definition. If a definition in the file is meant to be ext
- Service Intent must be explicit的解决方法
- KMP算法模板
- [区块链]Hyperledger Fabric源代码(基于v1.0 beta版本)阅读之乐扣老师解读系列 (二)Fabric模块分析
- svn命令在linux下的使用
- 虚拟机的类加载的时机
- MyBatis代码自动生成(利用命令)
- Error RawText ** must be wrapped in an explicit <Text> component 问题解决
- php扩展安装
- 远程升级过程
- 详解ROC/AUC计算过程
- [centos] 网卡设置学习
- 解决 JSP 页面报错 equal symbol expected
- Graphics.DrawString 方法
- Android 多个事件分发和处理
- dao类没有实现类,是怎样找到对应的sql 语句的