[英]React Native : Return conditional Statement in View
我面临一个奇怪的问题。 在我的本机反应应用程序中,我有条件呈现View
和ScrollView
。 问题是 false 语句首先显示在 true 语句之前,所以我在下面的示例中假设PinCodeVisible.showPinLock is true
,因此Pincode
应该显示而不是文本的 false 语句。 我的问题是它首先显示虚假陈述,即text
,然后在加载真实陈述即pincode
之后,我只想忽略虚假陈述下的text
,因为它是错误的,
为什么即使是虚假陈述也显示出来? 我错过了什么吗?
const [PinCodeVisible, setPin] = useState({ PINCodeStatus: "choose", showPinLock: false });
React.useEffect(() => {
setPin({ showPinLock: true}); //let say the pincode is true
}, [])
return (
<View style={styles.container} >
{PinCodeVisible.showPinLock === true ? (
<PINCode
// modalVisible={modalVisible}
status={PinCodeVisible.PINCodeStatus}
touchIDDisabled={true}
finishProcess={() => _finishProcess()}
timeLocked={5000}
/>
) :
<ScrollView style={styles.container}> //this scrollview shown first event the statement is true
<Text>This text will show before the true statement above</Text> // it should not shown because the statement is true
</ScrollView>}
</View>
)
const styles = StyleSheet.create({
container: {
flex: 1,
}
您可以检查以下内容,
const [pinCodeVisible, setPin] = useState({ PINCodeStatus: "choose", showPinLock: true });
setPin({... pinCodeVisible, showPinLock: true});
return (
<View style={styles.container}>
{(pinCodeVisible.showPinLock && (
<PINCode
finishProcess={() => _finishProcess()}
status={pinCodeVisible.PINCodeStatus}
timeLocked={5000}
touchIDDisabled={true}
/>
)) || (
<ScrollView style={styles.container}>
<Text>This text will show before the true statement above</Text>
</ScrollView>
)}
</View>
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.