【问题标题】:React Native Can't nest View Inside TextReact Native 不能在文本中嵌套视图
【发布时间】:2019-12-08 16:26:36
【问题描述】:
<View>
<Text>
{/* Adding notification if exists otherwise ignore */}
{post.hasNotification ? post.notifications: ''}
</Text>
</View>

如何将 View 组件包裹在 post.notifications 周围?当我这样做时,我得到一个错误,目前不支持带有文本的嵌套视图。我需要用一个 View 组件包装它,以便我可以设置它的样式。

【问题讨论】:

  • 你能分享你的代码吗?
  • 我在上面分享了,或者我的问题解释得不好?
  • {post.hasNotification ? post.notifications: ' ' } 是我想要的代码,视图组件包装了 post.notifications
  • 你不能在 组件中使用

标签: reactjs react-native text view native


【解决方案1】:

您不能在 Text 组件中使用 View 组件。试试这个,

<View>
     {post.hasNotification ? <View><Text>post.notifications</Text></View> : ' '}
 </View>

【讨论】:

  • 将 ' ' 更改为 null 似乎可以使用您的代码修复它,谢谢。
  • reactnative.dev/blog/2020/07/06/… 从 RN 0.63 开始,现在可以在 Text 中包含 View 组件
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-09-23
  • 1970-01-01
  • 1970-01-01
  • 2018-11-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多