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

231
Views
TypeError: tableData.map no es una función
import { useState, useEffect } from "react"; export default function RenderTable(){ const [tableData, updateTableData] = useState([{id: 1, name: "name", price: 200, size: "size"}]); useEffect(()=>{ fetch("/api/ManageSite").then(value => updateTableData(value.json())); }, []); return( <table> <tbody> {tableData.map(value => <tr key={value.id}> <td>{value.name}</td> <td>{value.price}</td> <td>{value.size}</td> </tr> )} </tbody> </table> ) }

este error ocurre cuando uso la función de mapa en return() , pero si hago la misma función de mapa en useEffect() , funcionará bien, explique por qué.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Esto podría suceder porque está tratando de mapear un objeto y no una matriz, por lo que dice que no existe la función Object.map().

Primero, asegúrese de que el nuevo estado sea una matriz.

Luego, si puede obtener resultados diferentes de una matriz, al renderizar, para que no se bloquee la página, asegúrese de que está haciendo un mapa en una matriz

 {Array.isArray(tableData) && tableData.map(()=>{})
about 4 years ago · Juan Pablo Isaza Report

0

.json() devuelve una promesa, lo que significa que en ES6 necesita usar otro then . Asegúrese de que la respuesta del backend sea una matriz en formato JSON.
Entonces puedes simplemente:

 useEffect(()=>{ fetch("/api/ManageSite") .then(value => value.json()) .then(data => updateTableData(data)) }, []);

Porque no importa qué, incluso si obtiene y actualiza datos como lo hice correctamente, pero su respuesta de punto final no es una matriz. Seguirá ocurriendo el mismo error

about 4 years ago · Juan Pablo Isaza Report
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!