首页 > 解决方案 > React Native 不能在文本中嵌套视图

问题描述

<View>
<Text>
{/* Adding notification if exists otherwise ignore */}
{post.hasNotification ? post.notifications: ''}
</Text>
</View>

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

标签: reactjsreact-nativetextviewnative

解决方案


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

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

推荐阅读