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

67
Views
Node Js toma mucho tiempo para iniciar sesión en la consola

Hola, esta es mi primera pregunta en stackoverflow, perdónenme si pregunto algo mal. Estoy hecho botón si hago clic en él eliminará la cantidad por uno. Entonces, después de mostrar eso en UI. Estoy enviando los datos al servidor. Pero cuando registro en la consola el req.body, se tarda entre 20 y 30 segundos en mostrarlo. A veces parece que no pasó nada. aquí está el código

 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); });

}, [artículo])

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

Este es el código en el lado del cliente:

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

0

Pude resolver el problema cambiando el siguiente código:

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

a

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