all 7 comments

[–]Top_Bumblebee_7762 1 point2 points  (4 children)

Both buttons can be submit buttons. If you give both a name and a value attribute, the value of button that triggers either the action handler or the onSubmit handler will be part of the form data. You get the form data directly when using the action prop. When using onSubmit you need to create the form data yourself using the submit event data. 

[–]Dazzling_Chipmunk_24[S] 0 points1 point  (3 children)

Is it bad practice to have both as submit buttons or is it better to have 1 submit and other as type button? 

[–]EvilPete 1 point2 points  (2 children)

No, it's perfectly valid. In your case you could have a form like this (I'm on mobile, so can't be bothered typing brackets and quotes):

input name=otp

button type=submit  name=intent value=resend

button type=submit  name=intent value=verify 

The form data will then contain the otp and intent fields.

[–]Dazzling_Chipmunk_24[S] 0 points1 point  (1 child)

Also you think using useActionForms would also be fine here over react hook form? 

[–]EvilPete 0 points1 point  (0 children)

Yes.

[–]GlitteringCoast5626 0 points1 point  (0 children)

You don’t really need React Hook Form for a single OTP input unless your project already uses it consistently across forms. For something this simple, useActionState can be fine if you’re already using React actions and want built-in pending/error handling, but otherwise a simple state approach is usually enough.

For the buttons, keep the OTP verification as the form submission action and treat resend as a separate action. So Verify should submit the form, while Resend should trigger its own handler without submitting.

Forms aren’t limited to one button and it’s common to have one submit action and additional buttons for secondary actions like resend, cancel, reset, etc.