How do I reset form fields through a server action / server component?
I have a form where there is a simple input field and a button. After clicking the submit button, the form submits and data is sent through a server action.
How to I reset the form field while maintaining the component as a server component? I have see many solutions online where we would convert it into a client component and userefs/hooks etc to reset the form fields. Is there a way to do this through the server action / server component?
1 Reply
Although it's currently in Canary, you can use the new useActionState hook, which allows for easily resetting the fields.
If that is not an option you need to create a ref for the form, then inside the action use the ref to reset the fields.