Server Actions
Docs
Unstable (alpha)
Revalidate Tag
Key takeaways:
- Functions with
'use server'should have serializable arguments and a serializable return value - There are 3 ways to call such functions (first two support progressive enhancement):
actionprop on a formformActionprop on<button>,<input type="submit">, and<input type="image">in a formstartTransition
useOptimisticto implement optimistic updatesuseFormStatusto get the status of a form submission- We can't define server actions in client components, but we can pass them as props
- We can import server functions inside client components
- Two ways to revalidate a page:
revalidatePathrevalidateTag
- We can use
cookies()andheaders()functions in server actions - We can modify cookies (basically they are read-only)