[英]console.log() statement being called twice in Reactjs
My code is as follows:我的代码如下:
//fetch tasks from server
const fetchTasks=()=>{
const fTask = async ()=>{
const res = await fetch('http://localhost:5000/tasks')
const data = await res.json()
console.log("data", data)
}
fTask()
}
fetchTasks()
I was expecting the data to be logged into the console only once, but for some reason, it is being logged twice.我原以为数据只被记录到控制台一次,但由于某种原因,它被记录了两次。 I tried debugger, but it too did not help.. thank you in advance..我试过调试器,但它也没有帮助..提前谢谢你..
do this instead改为这样做
const fetchTasks= async ()=>{
const res = await fetch('http://localhost:5000/tasks')
const data = res.json()
console.log("data", data)
}
fetchTasks()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.