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

142
Views
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 answers
Answer question

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 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!