仅当变量为 true 时我才需要显示组件,基本上我将创建两个按钮,一个将变量设置为 false,另一个设置为 true。我正在尝试使用 Angular 的 * ngIf 想法。我需要这样的东西:
render() {
return (
<View>
<Button
title="Click me"
onPress={ () => { this.loading = true } }
/>
{this.loading ? <Modal /> : null}
</View>
);
}
看来你是新来的React,处于反应状态并且处理程序要么被保存在state或通过了props.
你可以通过像这样的组件状态来实现这一点show
,有点击处理程序来设置State然后在渲染中你可以检查this.state.show
并决定是否显示该组件
setShow = () = >{
this.setstate({show : true});
}
render() {
return (
<View>
<Button
title="Click me"
onPress={this.setShow}
/>
{this.state.show ? <Modal /> : null}
</View>
);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)