Next.js Discord

Discord Forum

The "correct" way to call server actions using React Hook Form,Zod, and useActionState().

Unanswered
Kooikerhondje posted this in #help-forum
Open in Discord
KooikerhondjeOP
Hello!

What is the correct way to call a server action using RHF?

Should I be calling it manually through a custom async onsubmit function?
- The problem I encountered with this is that I have to manually call "action" from useActionState within a useTransition().

OR, should I be using the "action" prop within the form tag? If so, how do I retain client-side validation with zod and RHF?
- Problem with this is that client-side validation breaks without calling "handleSubmit()" from RHF
- I'll have to programatically submit the form within the handleSubmit() function

Thanks for the help! (:

2 Replies

Barbary Lion
!up
Giant Angora
hi @Kooikerhondje,
if you read server action docs, they simply send POST request, and you can use them anywhere, so call serverAction in onSubmit handler anyway you want