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

190
Views
Activar o desactivar componentes de texto

¡Hola, hago una aplicación en React Native!

Intento hacer tres botones activos o no activos. Así que defino un estado con

 const [activeLabel, setActiveLabel] = useState(0);

Y en mi componente de texto tengo

 activeLabel === 1 ? styles.selectedLabel : styles.notSelectedLabel onPress={() => setActiveLabel(1)}

Cuando inicializo, configuro activeLabel en 0 y cuando hago clic y otro componente con console.log activeLabel permanece en 0.

hago algo mal?

Gracias !

Aquí mis etiquetas de componentes

 function Labels({ setDataNumber, title, color, firstLabel, secondLabel, thirdLabel, }) { const [activeLabel, setActiveLabel] = useState(0); return ( <View style={{ flexDirection: "row" }}> <Text style={{ color: color, fontSize: 20, margin: 10 }}>{title}</Text> <View style={{ flexDirection: "row", justifyContent: "flex-end", flex: 1 }} > <Text style={{ color: color, borderColor: color, ...(activeLabel === 0 ? styles.selectedLabel : styles.notSelectedLabel), }} onPress={() => setActiveLabel(0), () => setDataNumber(0)} > {firstLabel} </Text> <Text style={{ color: color, borderColor: color, ...(activeLabel === 1 ? styles.selectedLabel : styles.notSelectedLabel), }} onPress={() => setActiveLabel(1), () => setDataNumber(1)} > {secondLabel} </Text> <Text style={{ color: color, borderColor: color, ...(activeLabel === 2 ? styles.selectedLabel : styles.notSelectedLabel), }} onPress={() => setActiveLabel(2), () => setDataNumber(2)} > {thirdLabel} </Text> </View> </View> ); }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

¡@sidharth-rathi me ofreció una solución!

 function Labels({ setActiveLabel, title, color, activeIndex, labels = [] }) { return ( <View style={{ flexDirection: "row" }}> <Text style={{ color: color, fontSize: 20, margin: 10 }}>{title}</Text> <View style={{ flexDirection: "row", justifyContent: "flex-end", flex: 1 }} > {labels.map((el, index) => ( <Text style={{ color: color, borderColor: color, ...(activeIndex === index ? styles.selectedLabel : styles.notSelectedLabel), }} onPress={() => setActiveLabel(index)} > {el} </Text> ))} </View> </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!