We can start utilizing server actions by refactoring our POST handler for creating a customer into a server action.
You will need to add the serverActions: true
flag to your next config under the experimental
settings.
In this example we will refactor a form that utilizes react-query
and react-hook-form
that sends a POST request to an API route that we have set up to add customers to.
Server Actions make it easy to grab form data and submit data directly in that action on the server.