Next.js Discord

Discord Forum

why useActionState removes data on submit form ?

Answered
Scaly-naped Pigeon posted this in #help-forum
Open in Discord
Scaly-naped PigeonOP
is there anyway to useActionState without removing the input forms because when I submit the form and get error on submitting everything is removed and I have to fill out the form again
Answered by Asian black bear
This is not a cause of useActionState but a change in React 19 itself. The intended way to deal with this is to return the input values as part of the return value of your handler so that your form can set the initial values based on those.

An alternative is to revert the behavior using this: https://discord.com/channels/752553802359505017/752647196419031042/1298121445880107059
View full answer

2 Replies

Asian black bear
This is not a cause of useActionState but a change in React 19 itself. The intended way to deal with this is to return the input values as part of the return value of your handler so that your form can set the initial values based on those.

An alternative is to revert the behavior using this: https://discord.com/channels/752553802359505017/752647196419031042/1298121445880107059
Answer
Scaly-naped PigeonOP
thank you so much @Asian black bear its working great, i had so much trouble dealing with this but your solution is great 🙂