我仍然很陌生,直到现在我仍然无法理解当用户单击特定按钮时如何删除视图。例如,假设我有以下代码块:
import React, { Component } from 'react'
import { AppRegistry, View, Text, TouchAbleOpacity } from 'react-native'
class Example extends Component {
removeView(){
// what should I do here?
}
render(){
return (
<View>
<View> // View to be removed
<TouchAbleOpacity onPress={() => this.removeView()}>
<Text>Remove View</Text>
</TouchAbleOpacity>
</View>
</View>
)
}
}
AppRegistry.registerComponent('example', () => Example);
Run Code Online (Sandbox Code Playgroud)
如何以编程方式删除 View 元素?