React Native 无法在文本中嵌套视图

React Native Can't nest View Inside Text

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

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

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

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