【发布时间】:2021-01-11 06:32:54
【问题描述】:
技术:React-Native
DesiredResult:我希望 this.state.vis 可解释(作为布尔值)。这应该初始化为true,但是,在单击按钮时,状态必须设置为false,从而使可见性为假。
Bug:位于渲染下的if-condition。这行代码无法识别this.state.vis(只能识别this.props.vis)
class ModalSectionCard extends React.Component <{vis:boolean,cardText:string}>{
constructor(props:any){
super(props);
this.state ={
vis: this.props.vis
};
}
render(){
if (this.state.vis){
return(
<TouchableOpacity onPress={()=> this.setState({vis:false})}>
<View style={{backgroundColor:"#333366"}}>
<ModalSecCard >
<Text style={{color:"#fff"}}>{this.props.cardText}</Text>
</ModalSecCard>
</View>
</TouchableOpacity>
)
} else{
return null
}
}
}
【问题讨论】:
标签: reactjs react-native state tsx