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

5 messages ยท Page 1 of 1 (latest)

dim walrus
#

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.

little horizonBOT
#

๐Ÿ”Ž This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

      ๐Ÿ•ต๏ธ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in <id:customize>

      โœ… You can mark a message as the answer for your post with `Right click -> Apps -> Mark Solution`
      (if you don't see the option, try refreshing Discord with Ctrl + R)
gentle osprey
#

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

#

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

dim walrus
#

Awesome, thanks for your help ๐Ÿ™‚