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

190
Vistas
React, nothing is shown after looping through an array of data with map method

Just started leaning Reac. Trying to build a simple App, which shows the list of Tasks. However when I run the App, it does not show anyout in the browser. There is no error in the console or anything. Not sure what is missing here.

Here is the code:

  1. App.js
import React from 'react';
import TaskList from './TaskList';

function App() {

  const tasks = [
    {id:0,description:"1st Task",isDone:false},
    {id:1,description:"2st Task",isDone:false}
  ]

  return (
    <div>      
     <TaskList tasks={tasks} />
    </div>
  );
}
export default App;
  1. TaskList.js
import React from "react";
import Task from "./Task";

export default({ tasks }) => {
    return (
        <ul className="list-group">
        { 
        tasks.map(task => {            
            <li key={task.id} className="List-group-item">
                <Task task={task} />
            </li>
        })}
      </ul>
    )
}
  1. Task.js
import React from "react";
export default ({task}) => {
    return(  
        <p>
         {task.description}
        </p>     
    )
}

The list of tasks are not shown in the screen, neither there is any error in console.

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

Here is where you are doing wrong, in your map function in TaskList.js you are not returning anything. Try with this :

import React from "react";
import Task from "./Task";

export default({ tasks }) => {
    return (
        <ul className="list-group">
        { 
        tasks.map(task => {
        
            return (<li key={task.id} className="List-group-item">
                      <Task task={task} />
                   </li>)
        })}
      </ul>
    )
}
about 4 years ago · Juan Pablo Isaza Denunciar

0

In your TaskList component you didn't return anything you need to replace { by (

import React from "react";
import Task from "./Task";

export default ({ tasks }) => {
  return (
    <ul className="list-group">
      {tasks.map((task) => (
        <li key={task.id} className="List-group-item">
          <Task task={task} />
        </li>
      ))}
    </ul>
  );
};

about 4 years ago · Juan Pablo Isaza Denunciar

0

You are not returning anything in your .map() loop. It Should be

 tasks.map(task => {            
          return  <li key={task.id} className="List-group-item">
                <Task task={task} />
            </li>
        })}

Or since you don't have any other logic inside your callback function you can just remove the brackets and the arrow function will return the single jsx statement by default.

{tasks.map((task) => 
        <li key={task.id} className="List-group-item">
          <Task task={task} />
        </li>
      )}
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