Hey everyone 👋,
Need some help with state management using Next.js Server Actions and useActionState for a profile edit form.
I have a client component with conditional Edit/Save/Cancel buttons. Facing a few tricky issues:
⭐ Post-Save "Edit" Flicker: After a successful save, clicking the "Edit" button immediately switches back to view mode until page refresh.
⭐Input Values Reset on Error: If validation fails (action returns errors), input fields revert to their initial defaultValue instead of keeping the user's input.
⭐Errors Persist on Cancel: After a failed save (errors visible), clicking "Cancel" exits edit mode and resets values (to defaultValue), but the validation error messages remain on screen.
Any insights on managing state (isEditing, input values, formState) in these scenarios would be awesome! Happy to share code snippets if needed.
I attached the code
Thanks!