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

194
Views
I wanna delete a post from my UI but I have a problem

I want to delete a post from my UI. I already did app.delete in my server site. I use MongoDB and nodejs for the server.

const ManageItem = () => {
    const navigate = useNavigate();
    const [items, setItems] = useItems();


    const handleToNavigate = () => {
        navigate('/additem')
    }

    const handleDelete = id => {
        const proceed = window.confirm('Are you sure you want to delete?');
        if (proceed) {
            const url = `http://localhost:5000/item/${id}`;
            fetch(url, {
                method: 'DELETE'
            })
                .then(res => res.json())
                .then(data => {
                    console.log(data);
                    const remaining = items.filter(item => item._id !== id);
                    setItems(remaining);

                })
        }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Your question is very unclear. For now I can only assume that you are filtering out the deleted data and setting the rest of the data in a state. Either you are not loading the state in the ui properly or there is something wrong in your server side. Please provide your code for better understanding. Till then try this out in your server side, if you haven't already.

app.delete("/item/:id", async (req, res) => {
      const id = req.params.id;
      const query = { _id: ObjectId(id) };
      const result = await databaseCollection.deleteOne(query);
      res.send(result);
    });
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!