我正在学习NextJS,遇到以下错误:
const QuoteCard = ({ post }) => {
const handleEdit = (post) => {
router.push(`/update-quote/${post._id.toString()}`);
};
const handleDelete = async (post) => {
const hasConfirmed = confirm(
"Are you sure you want to delete this quote?"
);
if (hasConfirmed) {
try {
await fetch(`/api/quote/${post._id.toString()}`, {
method: "DELETE",
});
const filteredPosts = myPosts.filter((item) => item._id !== post._id);
setMyPosts(filteredPosts);
} catch (error) {
console.log(error);
}
}
};
};
每当我尝试调用handleEdit或handleDelete函数时,我都会收到一条错误消息,指出post._id未定义。然而,涉及“发布”的所有其他功能都工作正常。
我尝试将日志记录到控制台,它确实有一个“_id”属性,问题可能是什么?
很明显,从外门传过来的
post
的值没有“_id”字段。