Server Actions

This page demonstrates a Next.js Server Action, which allows forms and UI interactions to call server-side code directly without needing an API route. When the form below is submitted, the browser sends the data straight to the server action, which runs securely on the server.

Expected Behaviour

When you submit the form (which has the `action` attribute set to `addItem`), the value you enter is sent to the server and calls the `addItem` function. This function runs on the server. The submitted value is logged to the server console. No client-side JavaScript bundle is created for this action, and no API route is required.

Try It