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
Array of objects returns empty JSX elements

I'm working on a time management app for a client and I'm using react native. When the user creates a new task, the task information is then pushed into an array of objects. It's an empty initial state. But for some reason I have an empty card in the ScrollView. I've even tried to manually set if the title of the task is not empty then return the jsx element, but no luck. Any idea what I'm doing incorrectly.

The function to create tasks

  Create_Task = () => {
    let {daily, Title, TaskTime} = this.state;
    daily.shift();
    daily.push({ID: this.makeid(5), TaskName: Title, TaskTime: TaskTime});    
    this.setState({daily: [...this.state.daily, Title]});
  };

The initial state of the array and all the information

const initialState = [{ID: '', TaskName: '', TaskTime: ''}];
 this.state = {
   daily: initialState,      
   Title: '',
   TaskTime: '',
}

Returning JSX elements

<View style={styles.tasks}>
          <ScrollView>
            {this.state.daily.map(x => {
              if (x.TaskName !== ' '){
                return (
                <Card style={styles.card} key={x.ID}>
                  <View style={styles.cardView}>
                    <TouchableOpacity
                      style={styles.btnComplete}></TouchableOpacity>
                    <Text style={styles.task_Title}>{x.TaskName}</Text>
                    <Text style={styles.taskTime}>{x.TaskTime}</Text>
                  </View>
                  </Card>
                );    
              }              
            })}
          </ScrollView>
        </View>
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Your initial state has an Object in it when you are initialing it. Just initialing with an empty array should solve your problem.

const initialState = [];
 this.state = {
   daily: initialState,      
   Title: '',
   TaskTime: '',
}
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