【问题标题】:React Native: is it possible to make a component and all its children disappear?React Native:是否有可能使组件及其所有子项消失?
【发布时间】:2020-08-06 22:47:15
【问题描述】:
在我的 React Native 应用程序中,我有一个 <View>,其中嵌套了几个其他元素。通常,如果我想让一个组件消失,我会使其高度变为 0,使其不透明度为 0,等等。但我想要一种通用的方法来将样式应用于 <View> 并让它及其所有子组件消失。
有人知道我该如何处理吗?
【问题讨论】:
标签:
css
reactjs
react-native
react-native-stylesheet
【解决方案1】:
你可以在 jsx 中使用花括号内的条件来显示或隐藏组件
<View>
{
condition && (
<View> // <- View and its children will show only if condition is true
//Children components
</View>
)
}
</View>