{"id":16225900,"url":"https://github.com/bestguy/react-use-validated-state","last_synced_at":"2026-01-11T01:11:52.585Z","repository":{"id":33903339,"uuid":"163379060","full_name":"bestguy/react-use-validated-state","owner":"bestguy","description":"React hook for using state with validation","archived":false,"fork":false,"pushed_at":"2023-01-04T21:38:24.000Z","size":415,"stargazers_count":0,"open_issues_count":22,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-18T13:26:26.616Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bestguy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-12-28T07:13:33.000Z","updated_at":"2021-05-07T01:19:04.000Z","dependencies_parsed_at":"2023-01-15T03:15:58.318Z","dependency_job_id":null,"html_url":"https://github.com/bestguy/react-use-validated-state","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bestguy%2Freact-use-validated-state","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bestguy%2Freact-use-validated-state/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bestguy%2Freact-use-validated-state/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bestguy%2Freact-use-validated-state/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bestguy","download_url":"https://codeload.github.com/bestguy/react-use-validated-state/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246819749,"owners_count":20839094,"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-10-10T12:46:52.894Z","updated_at":"2026-01-11T01:11:52.540Z","avatar_url":"https://github.com/bestguy.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-use-validated-state\n\nReact hook for using state with validation.  Uses [validate.js](https://validatejs.org/)\n\n----\n\n## Syntax\n\n```javascript\nconst [state, setState, isValid, validationMessage, validate] =\n       useValidatedState(initialState, getValidationMessage, validateImmediately]);\n```\nReturns a stateful value, a function to update it, whether it's valid, and validation message (if invalid).\n\n\n### Parameters\n\n`initialState`\nThe initial state value.  During the initial render, the returned state is the same as this value.\n\n`getValidationMessage`\nOptional.  Function that receives the current state value, and returns a validation string if invalid, otherwise should return `undefined`;\n\nDefault value:\n`() =\u003e undefined`\n\n`validateImmediately`\nOptional.  Boolean value whether to validate on initial render, otherwise will validate after first change.\n\nDefault value:\n`false`\n\n### Return values\n\n`state`\nThe current state value.\n\n`setState`\nFunction used to update the state. It accepts a new state value and enqueues a re-render of the component.\n\n`isValid`\nA boolean value indicating if the state passes the validationConstraints.\nReturns undefined if validation has not been been run. \n\n`validationMessage`\nOptional.  A string describing the validation failures, if any.\n\n`validate`\nOptional.  Function used to trigger validation, even if state is unchanged.\nUseful for validating an unchanged value on blur.\n\n### Usage\n\n```javascript\nconst [username, setUsername, usernameValid, usernameValidationMessage, validateUsername] =\n       useValidatedState('', { presence: true, email: true });\nconst [pwd, setPwd, pwdValid, validatePwd] =\n       useValidatedState(password, { presence: true, length: { minimum: 6 } });\n\nreturn (\n  \u003cform\u003e\n    \u003cdiv\u003e\n      \u003clabel\u003eUsername\u003c/label\u003e\n      \u003cinput\n        value={username}\n        onChange={e =\u003e setUsername(e.target.value)}\n        onBlur={() =\u003e validateUsername()}\n      /\u003e\n      \u003cdiv\u003e{usernameMessage}\u003c/div\u003e\n    \u003c/div\u003e\n    \u003cdiv\u003e\n      \u003clabel\u003ePassword\u003c/label\u003e\n      \u003cinput\n        type=\"password\"\n        value={pwd}\n        onChange={e =\u003e setPwd(e.target.value)}\n        onBlur={() =\u003e validatePwd()}\n      /\u003e\n      \u003cdiv\u003e{pwdMessage}\u003c/div\u003e\n    \u003c/div\u003e\n    \u003cinput type=\"submit\" disabled={usernameValid \u0026\u0026 pwdValid} value=\"Sign Up\" /\u003e\n  \u003c/form\u003e\n);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbestguy%2Freact-use-validated-state","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbestguy%2Freact-use-validated-state","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbestguy%2Freact-use-validated-state/lists"}