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

139
Visualizações
How to populate ToDo list with UseEffect Axios API call in React?

I'm trying to populate my ToDo list with all the tasks I get from my database with an API call. Unfortunately, nothing is showing up. My API call is working because the console.log(response.data) returns the 3 tasks in my database, but my view is not updating with the data that I got from my call. I get no errors.

import axios from "../axios";
import {useState, useEffect } from "react";
import {ToDoFull,ToDoInner,Id,Title,Description} from "./StyledComponents.js";

const Tasks = () => {
    const [tasks, setTasks] = useState([]);

    useEffect(() => {
        const fetchAllItems = async () => {
            try {
                const response = await axios.get("/tasks/all-tasks");
                if (response.data !== "") {
                    console.log(response.data); //Prints out my three objects in an array in my console. works great
                    let objects = response.data.map(JSON.stringify);
                    let uniqueSet = new Set(objects);
                    let uniqueArray = Array.from(uniqueSet).map(JSON.parse);
                    setTasks(uniqueArray);
                } else {
                }
            } catch (err) {
                console.log(err);
            }
        };
        fetchAllItems();
        return () => {
            setItems([]);
        };
    }, []);

    return (
        <>
            <ToDoFull>
                {tasks.map((task) => {
                    <ToDoInner>
                        <ID>{task.taskid}</Title>
                        <Title>{task.title}</Title>
                        <Description>{task.description}</Description>
                    </ToDoInner>;
                })}
            </ToDoFull>
        </>
    );
};

export default Tasks;
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Please provide return inside tasks.map()

 <ToDoFull>
                {tasks.map((task) => {
                  return  (<ToDoInner>
                        <ID>{task.taskid}</Title>
                        <Title>{task.title}</Title>
                        <Description>{task.description}</Description>
                    </ToDoInner>);
                })}
            </ToDoFull>
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