Hey everyone, I'm trying to create a CRUD app on R...
# orm-help
s
Hey everyone, I'm trying to create a CRUD app on React + Prisma + Sqlite but unsure how to proceed I'm trying to delete the post, so I have an express server and have created these functions:
app.delete('/posts/:id', deletePost);
export const deletePost = async (req: Request, res: Response) => {
const { id }: { id?: number } = req.params;
const post = await prisma.post.delete({
where: {
id: Number(id),
},
})
res.json(post)
};
Now I'm trying to link it with the <PostTable> page... So I have a PostList.ts page, which calls fetch in a UseEffect and gets all the posts then passes it to <PostTable posts={posts}> So in my PostTable.ts file, I have a posts.map () and then on the delete button, I'm trying to figure out how to delete it I'm really confused if I need to call useEffect, deletePost (which doesnt work), and then how do I update the page? Should I pass the setPosts from PostList to PostTable? Not sure if I need to call prisma or update the posts using setPosts
r
@Sam 👋 What error does
deletePost
give you? Could you log it using
try/catch
in your handler and check.