简体   繁体   中英

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.

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;
        })
);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM