Next.js Discord

Discord Forum

Would wrapping my "delete server action" in a form be considered "anti pattern"

Answered
Anhinga posted this in #help-forum
Open in Discord
AnhingaOP
Hi, I'm kinda new to web dev, so please bear with me 🙂

I have an overview page for showing all my products. I want to be able to delete products from the db. As of right now, i use a button client component with an onClick event handler that calls a server action. I just read that to fully utilize server actions i would need to call them from a form.

Now to my question: Would wrapping my button inside a form to fully make use of server actions be considered "anti pattern" or simply the wrong way to do it? The form would not take any inputs or textareas but simply signal the intent that the user wants to delete a particular product.
Answered by fuma
This wouldn't be considered an anti-pattern since server actions are built for forms, it is absolutely fine to use server action to delete items
View full answer

3 Replies

This wouldn't be considered an anti-pattern since server actions are built for forms, it is absolutely fine to use server action to delete items
Answer
For now, only server actions can revalidate data on the client side without using client components, server action turns out to be the only option if you want to implement a form fully in RSC
AnhingaOP
Awesome, thanks for your help 🙂