Skip to content
Skillv1.0.0

formik

Build forms in React with Formik. Use when creating complex forms with validation, multi-step forms, dynamic form fields, or handling form submission with error states.

by terminalskills(0) 0 installs
Free
Sign in to install

Free account. Installing gives you the manifest plus copy-paste snippets.

See reviews

About

Imported from terminalskills/skills (skills/formik/SKILL.md). Install upstream with npx skills add terminalskills/skills --skill formik. Copyright stays with the author (Apache-2.0).

Formik

Overview

Formik manages form state in React — values, errors, touched fields, submission. Integrates with Yup/Zod for schema validation. Handles complex forms (multi-step, dynamic fields, arrays) without Redux or complex state management.

Instructions

Step 1: Basic Form

import { Formik, Form, Field, ErrorMessage } from 'formik'
import * as Yup from 'yup'

const SignupSchema = Yup.object({
  name: Yup.string().min(2).required('Name is required'),
  email: Yup.string().email('Invalid email').required('Email is required'),
  password: Yup.string().min(8, 'At least 8 characters').required('Password is required'),
})

function SignupForm() {
  return (
    <Formik
      initialValues={{ name: '', email: '', password: '' }}
      validationSchema={SignupSchema}
      onSubmit={async (values, { setSubmitting, setErrors }) => {
        try {
          await api.signup(values)
        } catch (err) {
          setErrors({ email: 'Email already registered' })
        } finally {
          setSubmitting(false)
        }
      }}
    >
      {({ isSubmitting }) => (
        <Form>
          <Field name="name" placeholder="Name" />
          <ErrorMessage name="name" component="span" className="error" />

          <Field name="email" type="email" placeholder="Email" />
          <ErrorMessage name="email" component="span" className="error" />

          <Field name="password" type="password" placeholder="Password" />
          <ErrorMessage name="password" component="span" className="error" />

          <button type="submit" disabled={isSubmitting}>Sign Up</button>
        </Form>
      )}
    </Formik>
  )
}

Step 2: Dynamic Field Arrays

import { FieldArray } from 'formik'

function TeamForm() {
  return (
    <Formik initialValues={{ members: [{ name: '', role: '' }] }} onSubmit={handleSubmit}>
      {({ values }) => (
        <Form>
          <FieldArray name="members">
            {({ push, remove }) => (
              <>
                {values.members.map((_, i) => (
                  <div key={i}>
                    <Field name={`members.${i}.name`} placeholder="Name" />
                    <Field name={`members.${i}.role`} as="select">
                      <option value="">Select role</option>
                      <option value="admin">Admin</option>
                      <option value="member">Member</option>
                    </Field>
                    <button type="button" onClick={() => remove(i)}>Remove</button>
                  </div>
                ))}
                <button type="button" onClick={() => push({ name: '', role: '' })}>
                  Add Member
                </button>
              </>
            )}
          </FieldArray>
        </Form>
      )}
    </Formik>
  )
}

Guidelines

  • For new projects, consider react-hook-form (less re-renders). Formik is still solid for existing projects.
  • Use schema validation (Yup/Zod) instead of manual validate functions.
  • setErrors in onSubmit handles server-side validation errors (duplicate email, etc.).
  • <ErrorMessage> only shows after field is touched — good UX by default.
  • For large forms, use enableReinitialize when initial values come from API.

Use it

Copy one of these into your project. Installing also returns the manifest and these snippets.

yaml
targets:
  - https://api.opensmartroute.ai/api/v1/registry/terminalskills-skills-formik/manifest   # or paste the manifest below

Manifest

An Open Capability Manifest: the router reads it to know what this does, what it costs and when to pick it.

terminalskills-skills-formik.ocm.jsonjson
{
  "ocm": "1",
  "id": "terminalskills-skills-formik",
  "kind": "skill",
  "name": "formik",
  "description": "Build forms in React with Formik. Use when creating complex forms with validation, multi-step forms, dynamic form fields, or handling form submission with error states.",
  "publisher": "terminalskills",
  "version": "1.0.0",
  "capabilities": {
    "domains": [
      "general"
    ],
    "tags": [
      "skill-md",
      "formik",
      "forms",
      "react",
      "validation",
      "ui",
      "skills-sh"
    ],
    "languages": [
      "en"
    ]
  },
  "quality_prior": 0.6,
  "examples": [
    "Build forms in React with Formik. Use when creating complex forms with validation, multi-step forms, dynamic form fields, or handling form submission with error states."
  ],
  "primary": false,
  "metadata": {
    "source": {
      "provider": "skills.sh",
      "repository": "https://github.com/terminalskills/skills",
      "path": "skills/formik/SKILL.md",
      "ref": "HEAD",
      "url": "https://github.com/terminalskills/skills/blob/HEAD/skills/formik/SKILL.md",
      "key": "terminalskills/skills/skills/formik/SKILL.md"
    },
    "compatibility": "React 16+",
    "license": "Apache-2.0"
  },
  "instructions": "# Formik\n\n## Overview\n\nFormik manages form state in React — values, errors, touched fields, submission. Integrates with Yup/Zod for schema validation. Handles complex forms (multi-step, dynamic fields, arrays) without Redux or complex state management.\n\n## Instructions\n\n### Step 1: Basic Form\n\n```tsx\nimport { Formik, Form, Field, ErrorMessage } from 'formik'\nimport * as Yup from 'yup'\n\nconst SignupSchema = Yup.object({\n  name: Yup.string().min(2).required('Name is required'),\n  email: Yup.string().email('Invalid email').required('Email is required'),\n  password: Yup.string().min(8, 'At least 8",
  "cost": {
    "context_tokens": 810
  }
}

Fetch it by URL: GET /api/v1/registry/terminalskills-skills-formik/manifest?version=1.0.0

Reviews

Star ratings from people who tried it. One review per account; edit yours any time.

No reviews yet. Install it, try it, and be the first to rate it.