NNext.js Feature Showcase
Server · Server actions

Server Actions

A form can call server-side code directly, with no API route. When the form is submitted, the browser sends the data straight to the server action, which runs securely on the server.

Expected behaviour

Submit the form and the value is sent to the server, which runs the addItem function and logs the value to the server console. The reply below comes from the server, including the server's time.

How this page works

  1. 1The form's action calls the addItem server action.
  2. 2Next.js packs up the form data and posts it to the server.
  3. 3addItem runs on the server, never in the browser.
  4. 4Its return value is sent back and shown on the page.

Live result