Skip to content

Commit

Permalink
examples: fix unhandled runtime error for forms (vercel#56600)
Browse files Browse the repository at this point in the history
Co-authored-by: Lee Robinson <me@leerob.io>
  • Loading branch information
MrNiceRicee and leerob committed Nov 16, 2023
1 parent 70389d0 commit f163dd0
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion examples/next-forms/app/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,16 @@ export async function createTodo(prevState: any, formData: FormData) {
const schema = z.object({
todo: z.string().min(1),
})
const data = schema.parse({
const parse = schema.safeParse({
todo: formData.get('todo'),
})

if (!parse.success) {
return { message: 'Failed to create todo' }
}

const data = parse.data

try {
await sql`
INSERT INTO todos (text)
Expand Down

0 comments on commit f163dd0

Please sign in to comment.