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

143
Vistas
React native conditional rendering an array with 2 conditions

I have an array with several objects. Inside each object i have a field called type that can be either a or b. I am trying to conditional render a specific view for type a and a specific view for type b.

Here is my array:

DATA=[
{id:1, type:'a'},{id:2,type:'b'}
]

return(
{DATA.type === 'a' ?

<Text>I am type A</Text>
:
<Text>I am Type B </Text>
}
)

When i do that nothing appears on the screen.

UPDATE

DATA=[
{id:1, type:'a',locked:true},
{id:2,type:'b',locked:false}
]

const[isLocked,setIsLocked]=useState(false)

return(

{isLocked && DATA.map((item) => item.type === 'a')) ?

<Text>I am type A</Text>
:
null}
)

it is still not working. I am type A still appears on all pages of my carousel.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You need to map your array to accomplish it. Otherwise, you can't get the correct key.

DATA = [
  { id:1, type:a },
  { id:2, type:b },
]

return(
  DATA.map((item) => item.type === 'a' 
    ? <Text>I am type A</Text>
    : <Text>I am Type B </Text>
))
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