Lesson 4.1

Writing your first server action

A server action is a function that only ever runs on the server but can be called from the client. It replaces the route handler you would otherwise write by hand.

Duration
8m
Level
Intermediate
Students
9.8k students

Overview

A server action is a function that only ever runs on the server but can be called from the client. It replaces the route handler you would otherwise write by hand.

In this lesson you will:

  • Define an action and call it from a form or an event
  • Revalidate the affected data after a write
  • Keep write credentials on the server side of the call

Resources

Next.js documentation

The official reference for the tools used in this lesson.