{"id":23727754,"url":"https://github.com/gbrogio/next-hook-form","last_synced_at":"2026-02-04T15:38:16.941Z","repository":{"id":253648757,"uuid":"844136105","full_name":"gbrogio/next-hook-form","owner":"gbrogio","description":"A hook for form validation in Next.js \u0026 React","archived":false,"fork":false,"pushed_at":"2024-08-18T14:07:40.000Z","size":56,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-10T04:24:05.927Z","etag":null,"topics":["form","form-validation","form-validation-react","hooks","nextjs","react","react-hooks"],"latest_commit_sha":null,"homepage":"https://next-hook-form.vercel.app","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/gbrogio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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-08-18T13:50:06.000Z","updated_at":"2024-08-18T14:10:13.000Z","dependencies_parsed_at":null,"dependency_job_id":"61affb01-1fba-4ce6-8e49-f08777b91334","html_url":"https://github.com/gbrogio/next-hook-form","commit_stats":null,"previous_names":["gbrogio/next-hook-form"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/gbrogio/next-hook-form","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gbrogio%2Fnext-hook-form","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gbrogio%2Fnext-hook-form/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gbrogio%2Fnext-hook-form/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gbrogio%2Fnext-hook-form/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gbrogio","download_url":"https://codeload.github.com/gbrogio/next-hook-form/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gbrogio%2Fnext-hook-form/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29088575,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-04T03:31:03.593Z","status":"ssl_error","status_checked_at":"2026-02-04T03:29:50.742Z","response_time":62,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["form","form-validation","form-validation-react","hooks","nextjs","react","react-hooks"],"created_at":"2024-12-31T01:29:58.633Z","updated_at":"2026-02-04T15:38:16.920Z","avatar_url":"https://github.com/gbrogio.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# useForm Hook\n\nThe `useForm` is a custom hook for managing forms in React, with support for schema validation using the `zod` library.\n\n## Installation\n\nTo use `useForm`, you need to have React and Zod installed in your project.\n\n```sh\nnpm install next-hook-form zod\n```\n\n## Usage\n\nHere is an example of how to use `useForm` in a React component:\n\n```tsx\n\"use client\";\n\nimport { useForm } from \"@/hooks/next-hook-form\";\nimport * as React from \"react\";\nimport { z } from \"zod\";\n\nexport default function Home() {\n  const { createRef, handleSubmit, isDirty, watch, isPending } = useForm({\n    schema: {\n      name: z.string().min(20),\n      name1: z.string().min(30),\n      terms: z.boolean().refine((v) =\u003e v, \"Fill terms!\"),\n    },\n  });\n\n  return (\n    \u003cmain className=\"h-screen flex items-center justify-center bg-gray-950 text-white\"\u003e\n      \u003cform onSubmit={handleSubmit(async () =\u003e {})} className=\"space-y-4\"\u003e\n        \u003cinput {...createRef(\"name\", \"change\")} type=\"text\" /\u003e\n        \u003cinput {...createRef(\"name1\")} type=\"text\" /\u003e\n        \u003cinput {...createRef(\"terms\")} type=\"checkbox\" /\u003e\n\n        \u003cbutton type=\"submit\" disabled={isDirty}\u003e\n          Submit\n        \u003c/button\u003e\n      \u003c/form\u003e\n    \u003c/main\u003e\n  );\n}\n```\n\n## API\n\n### `useForm`\n\n```typescript\nfunction useForm\u003cT extends SchemaType\u003e(opts: {\n  schema: T;\n}): {\n  createRef: \u003cK extends keyof T\u003e(\n    name: K,\n    dispareErrorOn?: \"submit\" | \"change\"\n  ) =\u003e {\n    ref: React.RefObject\u003cHTMLInputElement\u003e;\n    name: K;\n    onChange: () =\u003e void;\n  };\n  handleSubmit: (\n    cb: (inputs: any, error: string | null) =\u003e Promise\u003cvoid\u003e\n  ) =\u003e (ev: React.FormEvent\u003cHTMLFormElement\u003e) =\u003e void;\n  isDirty: boolean;\n  watch: (\n    names: (keyof T)[]\n  ) =\u003e { name: keyof T; value: string | boolean | null }[];\n  isPending: boolean;\n  error: string | null;\n  setError: (error: string | null, name?: keyof T) =\u003e void;\n  getValue: (name: keyof T) =\u003e string | boolean | null;\n  getInput: (name: keyof T) =\u003e HTMLInputElement | null;\n};\n```\n\n#### Parameters\n\n- `opts`: An object containing the validation schema.\n\n#### Returns\n\n- `createRef`: Creates a reference for an input field.\n- `handleSubmit`: Handles form submission.\n- `isDirty`: Indicates if any form field is dirty.\n- `watch`: Watches the values of specified fields.\n- `isPending`: Indicates if the form is in a pending state.\n- `error`: Contains the current error message.\n- `setError`: Sets an error message for a specific field or the entire form.\n- `getValue`: Gets the value of a specific field.\n- `getInput`: Gets the reference of a specific field.\n\n## License\n\nThis project is licensed under the MIT License. See the `LICENSE` file for more details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgbrogio%2Fnext-hook-form","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgbrogio%2Fnext-hook-form","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgbrogio%2Fnext-hook-form/lists"}