簡體   English   中英

在 Reactjs 中,console.log() 語句被調用兩次

[英]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()

我原以為數據只被記錄到控制台一次,但由於某種原因,它被記錄了兩次。 我試過調試器,但它也沒有幫助..提前謝謝你..

  1. 移除嚴格模式或將其變成 <> </> 片段快捷方式

改為這樣做

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM