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

187
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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