Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

213
Views
React Native: declaración condicional de devolución en vista

Estoy enfrentando un problema extraño. En mi aplicación nativa de reacción, tengo condiciones que representan View y ScrollView . El problema es que la declaración falsa se muestra primero antes de la declaración verdadera, por lo que tengo un ejemplo a continuación, digamos que PinCodeVisible.showPinLock is true , por lo que Pincode no debe mostrar la declaración falsa, que es el texto. Mi problema es que muestra primero la declaración falsa, que es el text , y luego, después de cargar la declaración verdadera, que es un pincode , solo quiero ignorar el text debajo de la declaración falsa, ya que es falso.

¿Por qué se muestra incluso si es una declaración falsa? ¿Me perdí algo?

 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, }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Puede verificar las siguientes cosas,

  1. Aquí, si desea mostrar una declaración verdadera en la carga de la página, debe establecer verdadero como un valor inicial de su estado, solo que no es necesario establecerlo en useEffect.

const [pinCodeVisible, setPin] = useState({ PINCodeStatus: "choose", showPinLock: true });

  1. Si desea actualizar un objeto, puede actualizar utilizando el operador de propagación.

setPin({ ... pinCodeVisible, showPinLock: true});

  1. En el método de renderizado, puede usar el operador condicional como se muestra a continuación
 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> );
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!