Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

194
Vistas
react native: Ternary condition inside Text component

Is it possible to make ternary condition so that if {title} contains part of text such as "appl" then 'styles.label' will be change to 'styles.label_2' .

const Field = ({ title, info }: Props) => {
  return (
    <View style={styles.container}>
      <Text style={styles.label}> {title} </Text>
      <Text style={styles.info}>{info ? info : ''} </Text>
    </View>
  );
};
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You can do that for sure.

The following checks if the title string contains appl and if so, use styles.label2 otherwise, use styles.label

<Text style={title.includes('appl') ? styles.label2 : styles.label}> {title} </Text>
about 4 years ago · Juan Pablo Isaza Denunciar

0

If you apply a second style only to hide when it evaluates to false, I prefer evaluating before rendering the component -- therefore if it evaluates to false, no component is ever present, instead of a empty one:

const Field = ({ title, info }: Props) => {
  return (
    <View style={styles.container}>
      <Text style={styles.label}> {title} </Text>
      {info && info.contains("appl") && (<Text style={styles.info}>{info} </Text>)}
    </View>
  );
};
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda