简体   繁体   English

第 55:11 行:期望一个赋值或 function 调用,而是看到一个表达式 no-unused-expressions

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

I want to update my state after a button clicked, below is a piece of update function handler codes where i tried to find the error and i couldn't, someone help me seems that line no.55 has an error.我想在单击按钮后更新我的 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;
        })
      );
    })
  }

You are not returning anything here:你在这里没有返回任何东西:

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

Instead, you can use an implicit return:相反,您可以使用隐式返回:

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

Or, an explicit one:或者,一个明确的:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ./src/index.js第36行:预期执行赋值或函数调用,而是看到一个表达式no-unused-expressions - ./src/index.js Line 36: Expected an assignment or function call and instead saw an expression no-unused-expressions Object.keys-需要一个赋值或函数调用,而是看到一个表达式no-unused-expressions - Object.keys - Expected an assignment or function call and instead saw an expression no-unused-expressions 如何解决这个 期望赋值或函数调用,而是看到一个表达式 no-unused-expressions - how to solve this Expected an assignment or function call and instead saw an expression no-unused-expressions 重定向(反应路由器dom),给出了期望的赋值或函数调用,而是看到了一个表达式no-unused-expressions - Redirect (react router dom) giving Expected an assignment or function call and instead saw an expression no-unused-expressions “预期分配或 function 调用,而是在我的聊天应用程序中看到一个表达式 no-unused-expressions” - “Expected an assignment or function call and instead saw an expression no-unused-expressions” in my chat app 得到预期赋值或函数调用的错误,而是看到一个表达式 no-unused-expressions? - Getting the error that Expected an assignment or function call and instead saw an expression no-unused-expressions? 得到预期的赋值或函数调用的错误,而是在反应中看到了一个表达式 no-unused-expressions - getting an error of Expected an assignment or function call and instead saw an expression no-unused-expressions in react 期望一个赋值或函数调用,而是在React中看到一个表达式no-unused-expressions错误 - Expected an assignment or function call and instead saw an expression no-unused-expressions error in React 在React中导入文件时,获得期望的赋值或函数调用,而是看到一个表达式no-unused-expressions - Getting Expected an assignment or function call and instead saw an expression no-unused-expressions, when import a file in React 反应:期望一个赋值或函数调用,而是看到一个表达式 no-unused-expressions - React: expected an assignment or function call and instead saw an expression no-unused-expressions
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM