Overrides
Form (TanStack)
Extended Features
Formwraps TanStack’suseForminstance in a native<form>and handlesform.handleSubmit()for you.useFormContextexposes the generic form instance.
Install
Configure your registry in components.json:
{
"registries": {
"@uxio": "https://ui.uxio.dev/r/styles/{style}/{name}.json"
}
}Then run:
npx shadcn@latest add @uxio/formThis installs @tanstack/react-form and zod as well.
Usage
import { useForm } from "@tanstack/react-form"
import { z } from "zod"
import { Form } from "@/components/ui/form"
const loginSchema = z.object({
email: z.string(),
password: z.string(),
})
export function LoginForm() {
const form = useForm({
defaultValues: {
email: "",
password: "",
} as z.infer<typeof loginSchema>,
validators: {
onSubmit: loginSchema,
},
onSubmit: async ({ value }) => {
// login
},
})
return (
<Form form={form}>
<form.Field
name="email"
children={(field) => {
//
}}
/>
</Form>
)
}import { useStore } from "@tanstack/react-form"
import { z } from "zod"
import { Button } from "@/components/ui/button"
import { useFormContext } from "@/components/ui/form"
const loginSchema = z.object({
email: z.string(),
password: z.string(),
})
function FormSubmit() {
const form = useFormContext<typeof loginSchema>()
const isSubmitting = useStore(form.store, (state) => state.isSubmitting)
return (
<Button loading={isSubmitting} type="submit">
Login
</Button>
)
}