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.