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

98
Vistas
ReactJS .map function wrong output

I'm currently programming a to-do list with the PERN stack. I have the following problem: when I "map" all todos I get the following output: {"description":"wash the dishes"}. My getTodos function:

const getTodos = async() => {
    try {
      const response = await fetch("http://localhost:5000/todos");
      const jsonData = await response.json();

      setTodos(jsonData);
    } catch (err) {
      console.error(err.message);
    }
  };



 // states
  const [todos, setTodos] = useState([]);

  useEffect(() => {
    getTodos();
  }, []);

A console.log(todos) outputs the following:

Array [ {…} ]
​
0: Object { todo_id: 9, description: "{\"description\":\"wash the dishes\"}" }
​
Length: 1
​
<prototype>: Array[]

map:

{todos.length != 0 &&
            todos.map((todo) => (
              <tr key={todo.todo_id}>
                <td>{todo.description}</td>
                <td>Edit</td>
                <td>Delete</td>
              </tr>
))}

returns {"description":"wash the dishes"}, but only "wash the dishes" should be output.

My backend getTodos function:

//get all todos

app.get("/todos", async (req, res) => {
  try {
    const allTodos = await pool.query("SELECT * FROM todo");
    res.json(allTodos.rows);
  } catch (err) {
    console.error(err.message);
  }
});
about 4 years ago · Juan Pablo Isaza
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