query string으로 코드를 짜봤습니다.
<span onClick={(e)=>{
fetch(`/api/post/delete?query=${a._id}`)}}>🗑️</span>
그럼 /api/post/delete.js 코드에는
import { connectDB } from "@/util/database";
import { ObjectId } from "mongodb";
export default async function handler(req,res){
if(req.method == 'GET'){
const db= (await connectDB).db('forum')
let result=await db.collection('post').deleteOne({ _id :new ObjectId(req.query) })
res.status(200).json('삭제완료')
} }
이렇게 작성했습니다 !
근데 삭제버튼을 눌러도 아무런 변화가 없습니다..구글링을 해봤는데도 해결되지가 않아서 여쭤봅니다 ㅠ