Server Actions
Server Actions are async functions that run on the server. They can be used in forms and called directly from client components.
Server Actions + useActionState
Form submissions are handled by a server action. The useActionState hook manages pending state and the response.
How it works
- 1. The form uses
action={formAction}instead of onSubmit - 2.
useActionStatereturns [state, formAction, isPending] - 3. The server action receives previous state and FormData
- 4. isPending is true while the action is running