exportdefaultfunctionPage() {// Server Actionasyncfunctioncreate() {'use server'// Mutate data }return'...'}
Can separate in different files
app/actions.ts
'use server'import { z } from'zod'constschema=z.object({ email:z.string({ invalid_type_error:'Invalid Email', }),})exportdefaultasyncfunctioncreateUser(formData:FormData) {constvalidatedFields=schema.safeParse({ email:formData.get('email'), })// Return early if the form data is invalidif (!validatedFields.success) {return { errors:validatedFields.error.flatten().fieldErrors, } }// Mutate data}