簡體   English   中英

第 55:11 行:期望一個賦值或 function 調用,而是看到一個表達式 no-unused-expressions

[英]Line 55:11: Expected an assignment or function call and instead saw an expression no-unused-expressions

我想在單擊按鈕后更新我的 state,下面是一段更新 function 處理程序代碼,我試圖在其中找到錯誤但我找不到,有人幫助我似乎第 55 行有錯誤。

const addUpdateStudentHandler =(mystudent) =>{
    axios.put(`http://localhost:3006/students/${mystudent.id}`, mystudent)
    .then(res=>{
      const{id, fullName, email} = res.data;
      console.log(res.data);
      setstudents(students.map((student) =>{
          student.id === id ? {...res.data} : student;
        })
      );
    })
  }

你在這里沒有返回任何東西:

setstudents(students.map((student) =>{
          student.id === id ? {...res.data} : student;
        })
);

相反,您可以使用隱式返回:

setstudents(students => students.map((student) => ({
          student.id === id ? {...res.data} : student;
        }))
);

或者,一個明確的:

setstudents(students => students.map((student) =>{
          return student.id === id ? {...res.data} : student;
        })
);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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