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

155
Views
"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 answers
Answer question

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 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!