TanStackT
TanStack4mo ago
5 replies
instant-harlequin

Need Help Server Fn Error with Zod

How to properly serialized zod error to client with serverFn and tanstack query
Project repo

// zod schema
const UpdateTodoIdAndName = createSelectSchema(todo, {
  name: schema => schema.min(1, { error: "this is required" }),
}).pick({ id: true, name: true });

// fn
const updateTodoFn = createServerFn()
  .inputValidator(UpdateTodoIdAndName)
  .handler(async ({ data }) => {
    const [post] = await db.update(todo).set({ name: data.name }).where(eq(todo.id, data.id)).returning();

    return post;
  });
GitHub
Contribute to gglennd/tanstack-start development by creating an account on GitHub.
GitHub - gglennd/tanstack-start at feat/orm
Was this page helpful?