Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

99
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!