#react hook form not working after submitting first post
1 messages · Page 1 of 1 (latest)
Based on the provided code and the information from the extracts, it's not entirely clear why the submit button isn't working as expected. However, there are a few things you could check:
-
Form Validation: You're using a form validation library (possibly zod (https://zod.dev/), as mentioned in the Next.js documentation (https://nextjs.org/docs/pages/building-your-application/data-fetching/forms-and-mutations)) with the
useFormhook fromreact-hook-form. If the form data doesn't pass the validation, thenewCommentfunction won't be called. Make sure the form data is valid according to yourcommentSchema. -
Async Function Handling: The
newCommentfunction is asynchronous, which means it returns a Promise. If there's an error in this function that isn't caught, it could cause the function to fail silently. Consider adding atry/catchblock inside thenewCommentfunction to catch and handle any errors. -
Form Submission: In your form, you're using
handleSubmit(newComment)fromreact-hook-formto handle form submission. Make sure that this is working correctly, and that the form is actually being submitted when you click the button. -
Server Actions: If you're using Next.js 13.4 or later, you might be using Server Actions (https://nextjs.org/blog/next-13-4) to handle form submissions. If this is the case, make sure your server action is correctly defined and is being called as expected.