Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

192
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda