[英]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.您好,这是我在stackoverflow 中的第一个问题,如果我问错了,请原谅我。 I'm made button if I click it it will delete quantity by one.如果我单击它,我将成为按钮,它将删除一个数量。 So after showing that on UI.所以在 UI 上显示之后。 I'm sending the data to server.我正在将数据发送到服务器。 But when I console log the req.body it taking 20-30s to show it.但是当我控制台记录 req.body 时,它需要 20-30 秒才能显示出来。 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');
})
I was able to resolve the issue by changing the following code:我能够通过更改以下代码来解决问题:
setItem({
...item,
...updateInfo});
to到
setItem(updateInfo);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.