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

186
Views
How can conditional rendering for array map

I have condition for profile page I want to show user profile data name . age etc..So I map array to get each user data but problem is when there is no data in firestore , this profile page is empty this is really disappointed I want to conditional rendering the following rendering But error is

jsx expression must have one parent element

so how can render this correctly


      
    return (

      <SafeAreaView style={styles.container}>
    
     {values.map((value)=>(

                  
<React.Fragment key={value.id}>
<View style={styles.header}></View>
<Image style={styles.avatar} source={{uri : value.photo}}/>
 <View style={styles.body}>
   <View style={styles.bodyContent}>
  
    <Text style={styles.name}>{value.displayName}</Text>
       
        <View style={styles.label}>
              <Text >My Job is - </Text>
                    <Text>{value.job}</Text>
        </View>
                   
              <View style={styles.label}>
              <Text>My Age is - </Text>
                    <Text >{value.age}</Text>
                </View>
                <View style={styles.label}>
                 <Text>My Gender is  - </Text>
                    <Text >{value.gender}</Text>
                  </View>
                  <View style={styles.label}>
                 <Text>I want to meet  - </Text>
                    <Text >{value.interestIn}</Text>
                   </View>
   </View>
  
 </View>

</React.Fragment>

     ))}

    

      <View style={tw("p-10 flex-row items-center justify-between px-5")}>
       <Pressable 
              
              style={
               tw('p-3 rounded-xl bg-red-400')} onPress={goedit}>
             <Text style={styles.text}>Edit Profile</Text>
             </Pressable>

             <Pressable 
              
              style={
               tw('p-3 rounded bg-red-400')} onPress={logout}>
             <Text style={styles.text}>LOGOUT</Text>
             </Pressable>
       </View>
        
  </SafeAreaView>

      
    )

I want to show user profile page as template even no data in firestore can someone help me

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

  const renderValues = () => {
    values.map((value) => {
      if (value) {
        return (
          <React.Fragment key={value.id}>
            <View style={styles.header} />
            <Image style={styles.avatar} source={{ uri: value.photo }} />
            <View style={styles.body}>
              <View style={styles.bodyContent}>
                <Text style={styles.name}>{value.displayName}</Text>

                <View style={styles.label}>
                  <Text>My Job is - </Text>
                  <Text>{value.job}</Text>
                </View>

                <View style={styles.label}>
                  <Text>My Age is - </Text>
                  <Text>{value.age}</Text>
                </View>
                <View style={styles.label}>
                  <Text>My Gender is - </Text>
                  <Text>{value.gender}</Text>
                </View>
                <View style={styles.label}>
                  <Text>I want to meet - </Text>
                  <Text>{value.interestIn}</Text>
                </View>
              </View>
            </View>
          </React.Fragment>
        );
      } else {
        return <View>no data</View>;
      }
    });
  };

  return (
    <SafeAreaView style={styles.container}>
      <>
        {renderValues()}

        <View style={tw('p-10 flex-row items-center justify-between px-5')}>
          <Pressable style={tw('p-3 rounded-xl bg-red-400')} onPress={goedit}>
            <Text style={styles.text}>Edit Profile</Text>
          </Pressable>

          <Pressable style={tw('p-3 rounded bg-red-400')} onPress={logout}>
            <Text style={styles.text}>LOGOUT</Text>
          </Pressable>
        </View>
      </>
    </SafeAreaView>
  );
about 4 years ago · Juan Pablo Isaza Report

0

Just add a <> ontop of the map and then </> on the bottom to close it. If you need flex then you can switch out the <></> for

about 4 years ago · Juan Pablo Isaza Report

0

You could try something like this, but paste your logic inside if statement:

const renderValues = () => {
    values.map((value) => {
      if (value) {
        return (
          <View>
            <Text>data</Text>
          </View>
        );
      } else {
        return <View>no data</View>;
      }
    });
  };

  return <>{renderValues()}</>;
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!