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

60
Vistas
Node Js taking to much time to console log

Hello This is my first question in stackoverflow please forgive me if I ask something wrong. I'm made button if I click it it will delete quantity by one. So after showing that on UI. I'm sending the data to server. But when I console log the req.body it taking 20-30s to show it. Sometimes it looks likes nothing happend. here is the code

  const handleDeliver = () => {
const newQuantity = parseInt(item?.quantity) - 1;
const newSold = parseInt(item?.sold) + 1;
if (newQuantity >= 0) {
  const updateInfo = {
    quantity: newQuantity + "",
    sold: newSold + "",
  };
  setItem({
    ...item,
    ...updateInfo,
  });
} else {
  toast.warning("Please Restock the Car.");
}

};

  useEffect(() => {
fetch(`http://localhost:5000/items/${id}`, {
  method: "PUT", // or 'PUT'
  headers: {
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    quantity: item?.quantity,
    sold: item?.sold,
  }),
})
  .then((response) => response.json())
  .then((data) => {
    toast("Success:", data);
  });

}, [item])

return(
      <MDBBtn
          className="w-100 my-5"
          color="danger"
          onClick={() => {
            handleDeliver();
          }}
        >
          Delivered
        </MDBBtn>

This is the code on client side:

    app.put('/items/:id', async (req, res) => {
        console.log(req.body);
        res.status(500).send('testing');
    })
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I was able to resolve the issue by changing the following code:

setItem({
...item,
...updateInfo});

to

setItem(updateInfo);
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