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
- 1The form's
actioncalls theaddItemserver action. - 2Next.js packs up the form data and posts it to the server.
- 3
addItemruns on the server, never in the browser. - 4Its return value is sent back and shown on the page.