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

149
Views
"TypeError no detectado: inventarios.map no es una función".?

Después de eliminar un elemento de la base de datos y actualizar la interfaz de usuario con gancho, aparece este error que dice

 "Uncaught TypeError: inventories.map is not a function".

¿Qué podría estar mal con mi código y cómo resolver este problema? Aquí está el código completo:

 const ManageInventories = () => { const [inventories, setInventories] = useInventory() const handleDeleteItem = (id) => { fetch(`http://localhost:5000/manageinventories/${id}`, { method: 'DELETE', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ id }) }) .then((response) => response.json()) .then((data) => { setInventories(data) }) } return ( <div className="manage-inventories-style"> <h3 className="pt-3 mb-3">Manage Inventories</h3> <Container> <Table size="lg" striped bordered hover variant="dark"> <tbody> {inventories.map((inventory) => ( <InventoryDetails key={inventory._id} inventory={inventory} handleDeleteItem={handleDeleteItem}></InventoryDetails> ))} </tbody> </Table> <div className="mt-3 pb-5"> <Link className="manage-inventories-btn d-flex align-items-center justify-content-center w-25 mx-auto" to="/additem"> Add new Item <FontAwesomeIcon className="me-2 ms-2" icon={faLongArrowAltRight}></FontAwesomeIcon> </Link> </div> </Container> </div> ) }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

El problema con sus cosas es que los inventarios son una promesa y el procesamiento se está ejecutando antes de que se resuelva la promesa.

 { inventories && inventories.map(inventory => <InventoryDetails key={inventory._id} inventory={inventory} handleDeleteItem ={handleDeleteItem} ></InventoryDetails>) }

también usa csn if else renderizado que será genial aunque

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!