Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

144
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda