[英]console.log() statement being called twice in Reactjs
我的代碼如下:
//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()
我原以為數據只被記錄到控制台一次,但由於某種原因,它被記錄了兩次。 我試過調試器,但它也沒有幫助..提前謝謝你..
改為這樣做
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.