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

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

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 Relatório

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 Relatório

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