{"id":22382372,"url":"https://github.com/jcoreio/zod-forms","last_synced_at":"2025-07-13T14:36:01.926Z","repository":{"id":248066507,"uuid":"827662023","full_name":"jcoreio/zod-forms","owner":"jcoreio","description":"A more seamless way to build React forms from Zod schemas","archived":false,"fork":false,"pushed_at":"2024-10-24T23:49:01.000Z","size":1225,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2024-11-25T03:13:15.811Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://jcoreio.github.io/zod-forms/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jcoreio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-12T05:53:27.000Z","updated_at":"2024-11-04T00:32:06.000Z","dependencies_parsed_at":"2024-10-23T03:14:01.933Z","dependency_job_id":"e72bf96a-bfd5-4841-9237-22ff0b271220","html_url":"https://github.com/jcoreio/zod-forms","commit_stats":null,"previous_names":["jcoreio/zod-forms"],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcoreio%2Fzod-forms","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcoreio%2Fzod-forms/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcoreio%2Fzod-forms/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcoreio%2Fzod-forms/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jcoreio","download_url":"https://codeload.github.com/jcoreio/zod-forms/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228209941,"owners_count":17885595,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-05T00:12:42.611Z","updated_at":"2025-07-13T14:36:01.915Z","avatar_url":"https://github.com/jcoreio.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @jcoreio/zod-forms\n\nA more seamless way to build React forms from Zod schemas\n\n[![CircleCI](https://circleci.com/gh/jcoreio/zod-forms.svg?style=svg)](https://circleci.com/gh/jcoreio/zod-forms)\n[![Coverage Status](https://codecov.io/gh/jcoreio/zod-forms/branch/master/graph/badge.svg)](https://codecov.io/gh/jcoreio/zod-forms)\n[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)\n[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)\n[![npm version](https://badge.fury.io/js/%40jcoreio%2Fzod-forms.svg)](https://badge.fury.io/js/%40jcoreio%2Fzod-forms)\n\n# Features\n\n- 100% typesafe - Fully typechecked paths, input and output types for deeply nested fields\n- Supports `z.string().optional()`, `z.string().nullable()`, `z.number()` etc in inputs out of the box\n- Interprets blank inputs as `undefined` or `null` by default, depending on what the field schema\n  accepts\n- Normalizes inputs on blur by default (e.g. with `z.string().blur()` you'll see the trim on blur)\n- Supports Zod schemas with different input and output types (as long as you use\n  `zod-invertible` to specify how to format from output back to input)\n- Allows you to programmatically set either input or output values\n- Each step of a wizard form can declare its own submit handler independent from the enclosing\n  `\u003cform\u003e` element. This enables animated transitions between steps without a separate\n  `\u003cform\u003e`s or submit button for each step.\n\n# Limitations\n\n- Designed specifically for Zod and React only\n- Not currently focused on high performance/large form state like `final-form` or `react-hooks-form`\n- No async validate outside of submit right now\n\n# Quickstart\n\n## Installation\n\n```bash\npnpm i @jcoreio/zod-forms\n```\n\nor if you're using `npm`:\n\n```bash\nnpm i --save @jcoreio/zod-forms\n```\n\n## Create a form schema\n\nIn this example, we'll have a `url` field that must be a valid URL.\nUsing `.trim()` ensures that the submitted value will be trimmed.\nThe displayed value will also be trimmed whenever the field is blurred.\n\n```ts\nimport z from 'zod'\n\nconst schema = z.object({\n  url: z.string().trim().url(),\n})\n```\n\n## Create a form\n\n```ts\nimport { createZodForm } from '@jcoreio/zod-form'\n\nconst {\n  FormProvider,\n  // all of the following hooks can also be imported from '@jcoreio/zod-form',\n  // but the ones returned from `createZodForm` are already bound to the schema type\n  useInitialize,\n  useSubmit,\n  useFormStatus,\n  useHtmlField,\n} = createZodForm({ schema })\n```\n\n## Create a field component\n\n```ts\nimport { FieldPathForValue } from '@jcoreio/zod-form'\n\nfunction FormInput({\n  field,\n  type,\n  ...props\n}: Omit\u003cReact.InputHTMLAttributes\u003cHTMLInputElement\u003e, 'type'\u003e \u0026 {\n  type: HTMLInputTypeAttribute\n  // This ensures that only fields that accept string, null or undefined\n  // as input can be passed to \u003cFormInput\u003e\n  field: FieldPathForValue\u003cstring | null | undefined\u003e\n}) {\n  // This hook is designed to provide the smoothest integration with simple \u003cinput\u003es.\n  const { input, meta } = useHtmlField({ field, type })\n\n  const inputRef = React.createRef\u003cHTMLInputElement\u003e()\n  const error = meta.touched || meta.submitFailed ? meta.error : undefined\n  React.useEffect(() =\u003e {\n    inputRef.current?.setCustomValidity(error || '')\n  }, [error])\n\n  return (\n    \u003cinput\n      {...props}\n      // the `input` props from `useHtmlField` are designed to be spread here\n      {...input}\n      ref={inputRef}\n    /\u003e\n  )\n}\n```\n\n## Create the form component\n\n```tsx\nfunction MyForm() {\n  return (\n    // \u003cFormProvider\u003e wraps \u003cMyFormContent\u003e in a React Context through which the\n    // hooks and fields access form state\n    \u003cFormProvider\u003e\n      \u003cMyFormContent /\u003e\n    \u003c/FormProvider\u003e\n  )\n}\n\nfunction MyFormContent() {\n  // This hook initializes the form with the given values.\n  // The second argument is a dependency array -- the form will be reinitialized\n  // if any of the dependencies change, similar to React.useEffect.\n  useInitialize({ values: { url: 'http://localhost' } }, [])\n\n  // This hook sets your submit handler code, and returns an onSubmit handler to\n  // pass to a \u003cform\u003e\n  const onSubmit = useSubmit({\n    onSubmit: async ({ url }) =\u003e {\n      alert(`Submitted! url value: ${url}`)\n    },\n  })\n\n  const { submitting, pristine } = useFormStatus()\n\n  return (\n    \u003cform onSubmit={onSubmit}\u003e\n      \u003cFormInput\n        // this is how we bind \u003cFormInput\u003e to the `url` field\n        field={myForm.get('url')}\n        type=\"text\"\n        placeholder=\"URL\"\n      /\u003e\n      \u003cbutton disabled={pristine || submitting} type=\"submit\"\u003e\n        submit\n      \u003c/button\u003e\n    \u003c/form\u003e\n  )\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjcoreio%2Fzod-forms","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjcoreio%2Fzod-forms","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjcoreio%2Fzod-forms/lists"}