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

156
Vistas
"Uncaught TypeError: inventories.map is not a function".?

After deleting an item from the database and updating the UI with hook, I am getting this error saying

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

What could be wrong with my code and How to solve this issue? Here is the full code:

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 Respuestas
Responde la pregunta

0

The issue with your stuff is inventories is a promise and render is running before promise resolved

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

you also csn use if else rendering that will be great although

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