Next.js Discord

Discord Forum

How to prevent form inputs from resetting?

Answered
Spectacled Caiman posted this in #help-forum
Open in Discord
Avatar
Spectacled CaimanOP
Sometimes after submit, the form inputs are cleared. I am using useFormState hook.
Image
Answered by Ray
then put it to default value of the input
<input type='text' name='email' defaultValue={state?.values?.email} />
View full answer

7 Replies

Avatar
return the value from the server action then you can set the default value of the input from the form state
Avatar
Spectacled CaimanOP
Should I return formData from server action?
And use useState hook for form
Avatar
well, you can just return the errors with the previous value
Avatar
Spectacled CaimanOP
Okay thanks I will try
Avatar
then put it to default value of the input
<input type='text' name='email' defaultValue={state?.values?.email} />
Answer
Avatar
Spectacled CaimanOP
Thanks now working
Image