Skip to content
Skillpedia
Websites & UI (frontend)7.2k · #13311

tanstack-form

What it does

This skill guides the agent in using TanStack Form, a library for building forms with checks and clear types. It is for developers building forms that must validate user input before it is submitted.

When to use it

  • ✓When you need a form with validation for each field.
  • ✓When a form has lists of repeated fields that can grow or shrink.
  • ✓When you want form checks powered by a schema tool such as Zod.

Skill link

https://github.com/Kiranism/next-shadcn-dashboard-starter/blob/main/.agents/skills/tanstack-form/SKILL.md

Copy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.

How to use

The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.

Ready-to-paste message

Use this skill to help me: https://github.com/Kiranism/next-shadcn-dashboard-starter/blob/main/.agents/skills/tanstack-form/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
Want your AI to find skills like this on its own?Install the free Skillpedia MCP: one line, and it searches 15,000+ skills before each task.Install in 1 minute →

Example of what to ask your AI

“Build a sign-up form with name and email fields that checks each one before submitting.”

5 new skills a week. 1 minute to read.

How it works

The agent sets up the form with default values, checks and a submit handler, following the library's pattern. Field types are checked as the code is written, so mistakes are caught early.

Technical content (original SKILL.md)

Original text by the author, straight from GitHub.

Overview

TanStack Form is a headless form library with deep TypeScript integration. It provides field-level and form-level validation (sync/async), array fields, linked/dependent fields, fine-grained reactivity, and schema validation adapter support (Zod, Valibot, Yup).

Package: @tanstack/react-form Adapters: @tanstack/zod-form-adapter, @tanstack/valibot-form-adapter Status: Stable (v1)

Installation

npm install @tanstack/react-form
# Optional schema adapters:
npm install @tanstack/zod-form-adapter zod
npm install @tanstack/valibot-form-adapter valibot

Core: useForm

import { useForm } from '@tanstack/react-form';

function MyForm() {
  const form = useForm({
    defaultValues: {
      firstName: '',
      lastName: '',
      email: '',
      age: 0
    },
    onSubmit: async ({ value }) => {
      // value is fully typed
      await submitToServer(value);
    },
    onSubmitInvalid: ({ value, formApi }) => {
      console.log('Validation failed:', formApi.state.errors);
    }
  });

  return (
    <form
      onSubmit={(e) => {
        e.preventDefault();
        e.stopPropagation();
        form.handleSubmit();
      }}
    >
      {/* Fields */}
      <form.Subscribe
        selector={(state) => ({ canSubmit: state.canSubmit, isSubmitting: state.isSubmitting })}
        children={({ canSubmit, isSubmitting }) => (
          <button type='submit' disabled={!canSubmit}>
            {isSubmitting ? 'Submitting...' : 'Submit'}
          </button>
        )}
      />
    </form>
  );
}

Fields (form.Field)

<form.Field
  name="firstName"
  validators={{
    onChange: ({ value }) =>
      value.length < 3 ? 'Must be at least 3 characters' : undefined,
  }}
  children={(field) => (
    <div>
      <label htmlFor={field.name}>First Name</label>
      <input
        id={field.name}
        name={field.name}
        value={field.state.value}
        onBlur={field.handleBlur}
        onChange={(e) => field.handleChange(e.target.value)}
      />
      {field.state.meta.isTouched && field.state.meta.errors.length > 0 && (
        <em>{field.state.meta.errors.join(', ')}</em>
      )}
    </div>
  )}
/>

<!-- Nested fields use dot notation -->
<form.Field name="address.city">
  {(field) => (
    <input
      value={field.state.value}
      onChange={(e) => field.handleChange(e.target.value)}
      onBlur={field.handleBlur}
    />
  )}
</form.Field>

Validation

Validation Timing

Cause When
onChange After every value change
onBlur When field loses focus
onSubmit During submission
onMount When field mounts

Synchronous Validation

<form.Field
  name='age'
  validators={{
    onChange: ({ value }) => {
      if (value < 18) return 'Must be 18 or older';
      return undefined; // undefined = valid
    },
    onBlur: ({ value }) => {
      if (!value) return 'Required';
      return undefined;
    }
  }}
/>

Asynchronous Validation

<form.Field
  name='username'
  asyncDebounceMs={500}
  validators={{
    onChangeAsync: async ({ value }) => {
      const res = await fetch(`/api/check-username?q=${value}`);
      const { available } = await res.json();
      if (!available) return 'Username taken';
      return undefined;
    }
  }}
>
  {(field) => (
    <>
      <input value={field.state.value} onChange={(e) => field.handleChange(e.target.value)} />
      {field.state.meta.isValidating && <span>Checking...</span>}
    </>
  )}
</form.Field>

Schema Validation (Zod)

import { zodValidator } from '@tanstack/zod-form-adapter'
import { z } from 'zod'

const form = useForm({
  defaultValues: { email: '', age: 0 },
  validatorAdapter: zodValidator(),
  onSubmit: async ({ value }) => { /* ... */ },
})

<form.Field
  name="email"
  validators={{
    onChange: z.string().email('Invalid email'),
    onBlur: z.string().min(1, 'Required'),
  }}
/>

<form.Field
  name="age"
  validators={{
    onChange: z.number().min(18, 'Must be 18+'),
  }}
/>

Form-Level Validation

const form = useForm({
  defaultValues: { password: '', confirmPassword: '' },
  validators: {
    onChange: ({ value }) => {
      if (value.password !== value.confirmPassword) {
        return 'Passwords do not match';
      }
      return undefined;
    }
  }
});

Linked/Dependent Fields

<form.Field
  name='co
FAQ

Which frameworks does it support?

The skill lists React, Vue, Angular, Svelte, Solid and Lit, with React shown in its examples.

Can it check data with schemas?

Yes. It supports schema tools such as Zod and Valibot through adapter packages.

Do I need extra packages for basic forms?

The core form package is enough for basic use. Schema adapters are optional.

Details

Original description by the author

Headless, performant, and type-safe form state management for TS/JS, React, Vue, Angular, Solid, Lit, and Svelte.

repo: Kiranism/next-shadcn-dashboard-starter

Popularity

GitHub stars
7.2k
Ranking position
#13311
License
MIT
Updated
11/1/2026

Is this skill useful?

0

Sign in to vote.

Comments

  • …

More skills from this repository

Similar skills