{"_id":"@bswohlers/lightform","name":"@bswohlers/lightform","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@bswohlers/lightform","version":"1.0.0","description":"A simple & lightweight hook for building forms in React","main":"lib/index.js","types":"lib/index.d.ts","scripts":{"build":"tsc","format":"prettier --write \"src/**/*.ts\" \"src/**/*.js\"","lint":"tslint -p tsconfig.json","prepare":"npm run build","prepublishOnly":"npm run lint","preversion":"npm run lint","version":"npm run format && git add -A src","postversion":"git push && git push --tags"},"keywords":["react","form","hook"],"author":{"name":"Bill Wohlers"},"license":"ISC","devDependencies":{"@types/jest":"^28.1.6","@types/luxon":"^3.0.0","@types/react":"^18.0.26","jest":"^28.1.3","prettier":"^2.7.1","ts-jest":"^28.0.7","tslint":"^6.1.3","tslint-config-prettier":"^1.18.0","typescript":"^4.7.4"},"dependencies":{"react":"^18.2.0"},"gitHead":"be2770a2e8f35d807aca645740db7ba8d30b13f1","_id":"@bswohlers/lightform@1.0.0","_nodeVersion":"16.13.2","_npmVersion":"8.1.2","dist":{"integrity":"sha512-QuX+vF+8SD1OS+tZwNbmMqcFi9GmOEmSQJCndxyiaZccvNTXrUdq+TokwmHly+0xolIAKewpUI1UBpK+dc3fwA==","shasum":"927a90a8d10461a0ca77f2bb6c7f229eba33eb96","tarball":"https://registry.npmjs.org/@bswohlers/lightform/-/lightform-1.0.0.tgz","fileCount":4,"unpackedSize":5718,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIFqPkY6g1Wq5gwH7N+/OR8Zotztwan4lhxb6HVuBKtvEAiEAv0N2H3+hB6gvuYUqH32Euh6a5TeLiMNvRuAggIswwjs="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjvMdAACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmpf+A//XnX+OcpP14zLT+ujgFxOvk3AFeCz3tCAzVGusfGKa09aIZ/D\r\nixISQ1Fo3i7Bw/7Vw/A4r+8UecGWizh8k9Y8C+7XmE9i0zP+R88tfUNt9N0W\r\n+mkJw7djmREJ4+E9NZyHVNLgUePOyya8Q02sJtCRtkSfiSCumVlwkNtDPoha\r\nK872BeBBWjm5OSgJR7p8x8xdOlo8LBqMBrVdOzuJzWSWprOUwy9PXuMd0N3D\r\n4h6cnL6pn5VO4DEvCA9HIJ/JUEUHVCdpg9PfSKQAIn7180xAF6+iuRHaXT+R\r\ndsgqSIOoeeU9gQVb+uxkfOD0M4uB6eZt9PTx86rqEqLAaTZOsbdlGpWUjgiE\r\n1vbbZmYtFtMwyOUxFRpomlr05vsJGH3k7tLYeFB+1T1knGq9rQqp9JnHwCls\r\nwJcwDZN9HR/FfXmNf3XZwfSEBpERB9Zo2oj/4FIhzhkCi6kzCDnk6xpxbYCD\r\n7BJ9rNjaFRP8r51tTR3KfOaePeKOVWOk4z4y9pvoGwQ99OrBbzglDbeYLvUm\r\nqtZnpof/KCaSbcLJrBS+a4Zb8+ZqGtSiEfjqyHVvghdIiOZ3ArUtpxJb3+Di\r\nXS/OvUBf6xWiQIKRj//mXem1UfSu/UQazDEaMB/umamFA/udHM02balFfsuV\r\nKpk1vqGqn+EAxwPhg2YiH9Ta0my3CqN2UAM=\r\n=5cqX\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"bswohlers","email":"bswohlers@gmail.com"},"directories":{},"maintainers":[{"name":"bswohlers","email":"bswohlers@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/lightform_1.0.0_1673316159809_0.6225459907627888"},"_hasShrinkwrap":false}},"time":{"created":"2023-01-10T02:02:39.723Z","1.0.0":"2023-01-10T02:02:40.005Z","modified":"2023-01-10T02:02:40.217Z"},"maintainers":[{"name":"bswohlers","email":"bswohlers@gmail.com"}],"description":"A simple & lightweight hook for building forms in React","keywords":["react","form","hook"],"author":{"name":"Bill Wohlers"},"license":"ISC","readme":"# LightForm\nLightForm is a simple, lightweight hook for building forms in React. The simple and unopinionated API works with any kind of form built with React, even if you're not using react-dom.\n\n## Types\n### Validator<K>\n```\ntype Validator<K> = (value: unknown) => K;\n```\n\nA validator is a function that accepts any value and either returns the value (if it passes validation checks) or throws an error.\n\n## Hook\nLightForm exposes one hook, `useForm`. At a high level, `useForm` accepts the initial state of the form fields, and corresponding validators for any of those fields. Validators is a `Partial`, so not every field needs a validator function.\n\nThe hook returns the following object, assuming that the type of the form's state is `K`:\n\n```\n{\n  values: K;\n  errors: Record<keyof K, string>;\n  onFieldChange: (field: keyof K) => (value: K[keyof K]) => void;\n  hasErrors: boolean;\n}\n```\n\n### `values`\nAn object containing the current values of the form. This will have the same shape as the `initialState` passed into the hook.\n\n### `errors`\nAn object containing a map of field names to error messages. An empty error message (`\"\"`) indicates no error or the field has not yet been changed from its initial state. Note that if a field in `initialState` has an error, that error will not appear in this object until that field is modified. Therefore, use this object only for showing errors to the user and not for determining whether the form is submittable.\n\n### `onFieldChange`\nA function that, when called with a field name, returns an `onChange` function for that field, which is used to change the value of that field. \n\n### `hasErrors`\nA boolean indicating whether any of the fields in the form have errors. Note that this may be true even if `errors` has only empty strings; whereas the values of `errors` only populate after their fields have been modified, `hasErrors` will return true if the `initialState` contains an error. Therefore, use this to determine whether the form is submittable. ","readmeFilename":"README.md"}