tanstack-form
Skill1 starsChanged 6 months agoMITView on GitHub
Create or modify forms using TanStack Form's composition API. Uses formOptions() as the form shape primitive, withForm HOC for decomposing large forms into sections, withFieldGroup for reusable field groups across forms, Zod for validation, and i18n-prefixed error messages. Use when creating or modifying forms in the web app.
4 other projects use a version of this.
Adopted by
Most recently taken up by
- LaoitdevOpen/laoitdev-skillstheir own version, first seen Oct 20, 2026
- prdlk/skillstheir own version, first seen Oct 11, 2026
- Kiranism/next-shadcn-dashboard-startertheir own version, first seen Oct 8, 2026
- dvaJi/argostheir own version, first seen Sep 9, 2026
Other versions4 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 4
- Kiranism/next-shadcn-dashboard-starter★ 7.2ksame name
- dvaJi/argos★ 3same name
- prdlk/skills★ 1same name
- LaoitdevOpen/laoitdev-skills★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository4 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- hello-worldSkill
- ship-branch-giteaSkill
- ship-branchSkill
The file
Files
TanStack Form v2
For initial setup see setup.md. For withForm, withFieldGroup, and extendForm see composition.md. For array fields see arrays.md.
Rules
- Define form shape with
formOptions()— share it intouseAppFormand anywithFormsub-components via spread - Schemas live in the form file (or a sibling
schema.ts), never inside field components - Field components are dumb UI wrappers — they own no schema knowledge and no defaults
onSubmitonly callsmutation.mutate— side effects go inuseMutationcallbacks- Wrap
form.SubmitButtoninform.AppForm - Zod error messages: prefix with
"i18n:"if project uses i18n (checkpackage.jsonforreact-i18next) - Forms with 3+ distinct sections → split with
withFormHOC - Field groups reused across multiple forms →
withFieldGroupHOC renderinwithForm/withFieldGroupmust be a named function, not an arrow function (ESLint hooks rule)
Form Shape
formOptions() is the canonical primitive. Define it once; spread into useAppForm (and into withForm sub-components — see composition.md).
import { formOptions } from "@tanstack/react-form";
import { z } from "zod";
const schema = z.object({
name: z.string().min(1, "i18n:validation.required"),
email: z.string().email("i18n:validation.email"),
});
const opts = formOptions({
defaultValues: { name: "", email: "" },
});
// ---
const mutation = useMutation({
mutationFn: myServerFn,
onSuccess: () => { /* redirect, invalidate */ },
});
const form = useAppForm({
...opts,
validators: { onSubmit: schema },
onSubmit: ({ value }) => mutation.mutate({ data: value }),
});<form onSubmit={(e) => { e.preventDefault(); e.stopPropagation(); form.handleSubmit(); }}>
<form.AppField name="name">{(field) => <field.InputField label="Name" />}</form.AppField>
<form.AppField name="email">{(field) => <field.InputField label="Email" type="email" />}</form.AppField>
{mutation.isError && <p className="text-sm text-destructive">Something went wrong.</p>}
<form.AppForm>
<form.SubmitButton isLoading={mutation.isPending}>Submit</form.SubmitButton>
</form.AppForm>
</form>Adding a Field
Field components are pure UI. They read from context, render the input, show errors. They know nothing about schemas or defaults.
1. Create <name>-field.tsx — import useFieldContext from form-context, not form-setup
import { useFieldContext } from "../form-context";
import { useFormatError } from "src/lib/use-format-error";
export function MyField({ label, ...props }: { label: string } & Omit<ComponentProps<typeof UiComp>, "value" | "onChange" | "onBlur">) {
const field = useFieldContext<string>();
const formatError = useFormatError();
const error = field.state.meta.isValid ? undefined : formatError(field.state.meta.errors);
return (
<FormField label={label} error={error}>
<UiComp {...props} id={field.name} value={field.state.value}
onChange={(e) => field.handleChange(e.target.value)} onBlur={field.handleBlur} aria-invalid={!!error || undefined} />
</FormField>
);
}2. Register in form-setup.ts fieldComponents
3. Use at call site — all UI props go here, never inside the field component
<form.AppField name="x">{(field) => <field.MyField label="X" placeholder="…" />}</form.AppField>Common Mistakes
| Mistake | Fix |
| Schema or defaults inside a field component | Move to the form file |
const defaultValues = {} outside useAppForm | Use formOptions() |
Duplicating defaultValues in parent and withForm | Spread opts in both |
Server call in onSubmit | useMutation, call mutation.mutate in onSubmit |
SubmitButton unwrapped | Wrap in form.AppForm |
Field imports useFieldContext from form-setup | Import from form-context (avoids circular dep) |
Arrow fn in withForm/withFieldGroup render | Named fn: render: function Render({…}) {} |
Missing stopPropagation | Add both preventDefault + stopPropagation |
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

