Back to Cheatsheets
Next.js

Server Actions

Form handling and mutations

Implementation

3 items
CommandDescription
"use server"
Directive at top of file/fn
async function create(formData)
Action function
<form action={create}>
Invoke from form

Hooks

4 items
CommandDescription
useFormStatus()
Pending state
useFormState(action, initial)
Handle errors/result
revalidatePath("/path")
Refresh data
redirect("/new-path")
Navigate after action