All skills
skilld-dev avatar

/tanstack-vue-form-skilld

@b9c39cb

Use when writing, reviewing, or debugging code that imports @tanstack/vue-form (TanStack Form for Vue). Covers the 1.33.x API, including useForm, form.Field, form.FormGroup, form.Subscribe, form.useSelector, validators with Standard Schema, onDynamic with revalidateLogic, and array fields with mode="array". Result, forms built on current, non-deprecated Vue APIs with correct reactivity.

Use this Skill: https://skilld.dev/gh/skilld-dev/vue-ecosystem-skills/tanstack-vue-form-skilld

This session only. Nothing lands on disk.

referencesreactivity.md

≈797 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Reactivity in @tanstack/vue-form

Select form state in script setup

form.useSelector returns a Readonly<Ref> scoped to the selected slice (src/useForm.tsx:155-189, prepared source):

<script setup lang="ts">
const firstName = form.useSelector((state) => state.values.firstName)
const canSubmit = form.useSelector((state) => state.canSubmit)
</script>

<template>
  <p>{{ firstName }}</p>
</template>

form.useStore is the deprecated alias (src/useForm.tsx:190-192, 336-337). Use useSelector in new code.

Subscribe in the template

form.Subscribe takes an optional selector prop; the slot receives the selected state. Without selector, the whole form state is passed (src/useForm.tsx:338-349):

<form.Subscribe selector="(state) => ({ canSubmit: state.canSubmit, isSubmitting: state.isSubmitting })">
  <template v-slot="{ canSubmit, isSubmitting }">
    <button type="submit" :aria-disabled="!canSubmit">
      {{ isSubmitting ? '...' : 'Submit' }}
    </button>
  </template>
</form.Subscribe>

Source: official basic-concepts guide, https://tanstack.com/form/latest/docs/framework/vue/guides/basic-concepts

Do not use useField for reactivity

The standalone useField hook mounts and unmounts a FieldApi and is designed for use inside form.Field (src/useField.tsx:361-368). For reading state in script setup, use form.useSelector. The official docs state the same for the discouraged form.useField pattern.

Reactive field meta

Inside a form.Field slot, field.state is a computed that eagerly tracks isTouched, isBlurred, isDirty, errorMap, errorSourceMap, and isValidating (src/useField.tsx:260-322). Reading field.state.meta from a render function re-renders on meta updates; you do not need extra subscriptions for these flags.

Raw store access

useSelector and useStore are re-exported from @tanstack/vue-store (src/index.ts:2). Use them against form.store or field.store only when you need store-level control outside the provided helpers.

Listeners

React to triggers with the listeners prop; side effects belong there, not in validators:

<form.Field
  name="country"
  :listeners="{
    onChange: ({ value }) => {
      form.setFieldValue('province', '')
    },
  }"
>

Source: official basic-concepts guide. Listener hooks mirror validator hooks (onChange, onBlur, onMount, onSubmit).

Async initial values

Pass reactive default values built from computed refs so the form updates when data arrives (official guide, https://tanstack.com/form/latest/docs/framework/vue/guides/async-initial-values):

<script setup lang="ts">
import { reactive, computed } from 'vue'

const { data, isLoading } = useQuery({ queryKey: ['data'], queryFn: fetchPerson })

const defaultValues = reactive({
  firstName: computed(() => data.value?.firstName || ''),
  lastName: computed(() => data.value?.lastName || ''),
})

const form = useForm({ defaultValues, onSubmit: async ({ value }) => submit(value) })
</script>

<template>
  <p v-if="isLoading">Loading..</p>
  <form v-else @submit.prevent.stop="form.handleSubmit"><!-- ... --></form>
</template>

Source: SKILL.md on GitHub

No alerts8d3 checks · Risk SAFE
  • Gen Agent Trust Hub8d

    This skill serves as a comprehensive knowledge base and reference guide for the @tanstack/vue-form library. It includes API documentation, best practices, common issues, and community discussions. No malicious behavior, security vulnerabilities, or suspicious code patterns were detected.

  • Socket8d

    No alerts

  • Snyk9d

    Risk: LOW · No issues

Signed by skilld at b9c39cb. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub last week.

Activeupdated last week

README badge

README badge for skilld-dev/vue-ecosystem-skills/tanstack-vue-form-skilld