![](/img/trans.png)
[英]./src/index.js Line 36: Expected an assignment or function call and instead saw an expression 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.