{"id":29776842,"url":"https://github.com/godaddy/react-validation-context","last_synced_at":"2026-03-06T16:03:21.777Z","repository":{"id":10339295,"uuid":"65409763","full_name":"godaddy/react-validation-context","owner":"godaddy","description":"Components for providing validation via React context. ","archived":false,"fork":false,"pushed_at":"2023-12-18T04:14:19.000Z","size":718,"stargazers_count":7,"open_issues_count":5,"forks_count":10,"subscribers_count":28,"default_branch":"main","last_synced_at":"2025-09-30T23:37:31.587Z","etag":null,"topics":["reactjs","validation"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/godaddy.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-08-10T19:16:32.000Z","updated_at":"2023-10-25T21:30:02.000Z","dependencies_parsed_at":"2023-01-13T15:53:00.472Z","dependency_job_id":null,"html_url":"https://github.com/godaddy/react-validation-context","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/godaddy/react-validation-context","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/godaddy%2Freact-validation-context","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/godaddy%2Freact-validation-context/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/godaddy%2Freact-validation-context/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/godaddy%2Freact-validation-context/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/godaddy","download_url":"https://codeload.github.com/godaddy/react-validation-context/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/godaddy%2Freact-validation-context/sbom","scorecard":{"id":433358,"data":{"date":"2025-08-11","repo":{"name":"github.com/godaddy/react-validation-context","commit":"e2b1544f83c65d001b33274a9c5dde5d2b3f3ed8"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":4,"checks":[{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Code-Review","score":3,"reason":"Found 5/14 approved changesets -- score normalized to 3","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/ci.yaml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Pinned-Dependencies","score":3,"reason":"dependency not pinned by hash detected -- score normalized to 3","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yaml:14: update your workflow using https://app.stepsecurity.io/secureworkflow/godaddy/react-validation-context/ci.yaml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yaml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/godaddy/react-validation-context/ci.yaml/main?enable=pin","Info:   0 out of   2 GitHub-owned GitHubAction dependencies pinned","Info:   1 out of   1 npmCommand dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Branch-Protection","score":-1,"reason":"internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by integration","details":null,"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Security-Policy","score":9,"reason":"security policy file detected","details":["Info: security policy file detected: github.com/godaddy/.github/SECURITY.md:1","Info: Found linked content: github.com/godaddy/.github/SECURITY.md:1","Warn: One or no descriptive hints of disclosure, vulnerability, and/or timelines in security policy","Info: Found text in security policy: github.com/godaddy/.github/SECURITY.md:1"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 21 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":1,"reason":"9 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-968p-4wvh-cqc8","Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg","Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275","Warn: Project is vulnerable to: GHSA-fjxv-7rqg-78g4","Warn: Project is vulnerable to: GHSA-mwcw-c2x4-8c55","Warn: Project is vulnerable to: GHSA-9wv6-86v2-598j","Warn: Project is vulnerable to: GHSA-76p7-773f-r4q5","Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-19T03:55:45.123Z","repository_id":10339295,"created_at":"2025-08-19T03:55:45.124Z","updated_at":"2025-08-19T03:55:45.124Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30184885,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-06T14:42:24.748Z","status":"ssl_error","status_checked_at":"2026-03-06T14:42:14.925Z","response_time":250,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6: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":["reactjs","validation"],"created_at":"2025-07-27T10:20:39.178Z","updated_at":"2026-03-06T16:03:21.766Z","avatar_url":"https://github.com/godaddy.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-validation-context\n\nThere are several scenarios where a parent component's validation depends on\nwhether or not its descendant elements validate. By using the [React `context`\napi][react-docs-context], manual crawling of the React render tree can be\navoided. Instead, a handler function in the context can be called to update the\nparent's state whenever the descendant updates. This simplifies the\nimplementation of validation in the parent component.\n\n## Install\n\nThis package is available on `npm`. Install it using:\n\n```sh\nnpm install --save react-validation-context\n```\n\n## Usage\n\nThis library revolves around the idea of \"validity\". A component can have one of\nthe following validities:\n\n- `@typedef {(undefined|null|Boolean)} Validity`\n  - `undefined` - No validation state defined. This is the default.\n  - `null` - Validation is disabled.\n  - `true` - Validation passed.\n  - `false` - Validation failed.\n\nIt is useful to know when a component's validity changes. As such, this library\nattempts to provide a uniform API for validation change handlers. In general, a\nvalidity change handler has the following API:\n\n- `{Function} onValidChange` - Validity change handler.\n  - `@param {String} name` - The unique identifier for the component whose\n    validity changed.\n  - `@param {Validity} isValid` - The current validity of the component.\n  - `@param {Validity} wasValid` - The previous validity of the component.\n\nThe `name` identifier is also key to this library. It allows a collection of\ndescendants to be validated by a parent component. Essentially, this library\nprovides a way of tracking the validities of these various names. Note that this\nis **not** the same as tracking the validities of the components themselves,\nsince a component's name may change as well!\n\n## `Validates`\n\nThe `Validates` component is used to wrap a component that can be validated,\nproviding the logic for validation change handlers.\n\n### Props\n\n- `{String} name` - A unique identifier for the component. Required.\n- `{Validity} validates` - The component's validity.\n- `{Function} onValidChange` - Validity change handler.\n- `{ReactElement} children` - Children. The component only accepts a single\n  child, and will simply render as that child.\n\n#### When is the `onValidChange` handler called?\n\nThe function passed as the `onValidChange` prop will be called when:\n\n- The component mounts and the `validates` prop is not `undefined`\n- The component unmounts and the `validates` prop is not `undefined`\n- The component's `validates` prop changes\n\nDuring these cases, the `onValidChange` handler is called with:\n\n- The component's `name` prop\n- The component's validity\n- The component's previous validity\n\nHowever, if the component's `name` changes and the `validates` prop is not\n`undefined`, then the `onValidChange` handler will first be called with:\n\n- The previous `name` prop\n- `undefined`, to indicate that the previous `name` no longer has validation defined\n- The component's previous validity, if applicable\n\nThen, if the `validates` prop has changed, the `onValidChange` handler is called\n**a second time**.\n\n### Context\n\nIf `onValidChange` is present in `Validate`'s context, it will call that context\nhandler whenever the `onValidChange` handler in the props would be called, as\ndescribed above.\n\n### Example usage\n\n```jsx\nimport React from 'react';\nimport { string, func } from 'prop-types';\nimport { Validates } from 'react-validation-context';\n\n/**\n * An input that only validates when its value is non-empty and non-whitespace.\n */\nexport default class RequiredInput extends React.Component {\n  constructor(props) {\n    super();\n\n    // Set up the initial state based on whether the initial value validates\n    const { value, defaultValue } = props;\n    const validates = this.validate(value || defaultValue);\n    this.state = { validates };\n\n    this.onChange = this.onChange.bind(this);\n  }\n\n  // Check that the value exists and is non-whitespace\n  validate(value) {\n    return value \u0026\u0026 value.trim().length \u003e 0;\n  }\n\n  // Wrap the onChange handler to update `this.state.validates`\n  onChange(e) {\n    const { onChange } = this.props;\n    if (onChange) {\n      onChange(e);\n    }\n\n    const validates = this.validate(e.target.value);\n    this.setState({ validates });\n  }\n\n  render() {\n    const { onChange } = this;\n    const { onValidChange, name, ...inputProps } = this.props;\n    const { validates } = this.state;\n\n    // Set up `input` props\n    Object.assign(inputProps, { onChange, name });\n\n    // Render `input` and validation context-aware `Validates`\n    return \u003cValidates validates={ validates } onValidChange={ onValidChange } name={ name }\u003e\n      \u003cinput type='text' { ...inputProps } /\u003e\n    \u003c/Validates\u003e;\n  }\n}\n\nRequiredInput.propTypes = {\n  name: string.isRequired, // Input identifier name\n  value: string, // Input value\n  defaultValue: string, // Default input value\n  onChange: func, // onChange handler for input\n  onValidChange: func // validity change handler\n};\n```\n\n## `Validate`\n\nThe `Validate` component is used to wrap a component which has descendants that\nmay be validated, and provides an interface for validating all of those\ndescendants. It extends `Validates` to provide the same interface for listening\nfor validation changes on the component itself.\n\n**NOTE**: This component is able to keep track of all conforming descendant\ncomponents (not just direct children) via the [React `context` api][react-docs-context].\n\n### Props\n\n- `{Function} validate` - Validation function for descendants.\n  - `@param {Object} valids` - The keys are the descendant `name`s, and the\n    values are their `{Validity}`s.\n  - `@returns {Validity}` - The validity of this component.\n\nThis component also inherits all the props of `Validate`.\n\n#### When is the `validate` function called?\n\nThe function passed as the `validate` prop will be called whenever the component\nmust validate its descendants. This can occur when the component first mounts,\nor when at least one of its descendants has changed its name **or** validity.\n\nWhenever the `validate` function is called, it is given a single argument: an\n`Object` whose keys are the `name`s of the descendant components, and whose\nvalues are their validities. The `validate` function should then return the\nvalidity of the component.\n\n### Context\n\nIf `onValidChange` is present in `Validate`'s context, it will call that context\nhandler appropriately.\n\n### Example usage\n\n```jsx\nimport React from 'react';\nimport { string, func, node } from 'prop-types';\nimport { Validate } from 'react-validation-context';\n\nimport styles from './form.less';\n\nexport default class Form extends React.Component {\n  constructor() {\n    super();\n\n    // The form is initially valid\n    this.state = { validates: true };\n\n    this.onValidChange = this.onValidChange.bind(this);\n    this.onSubmit = this.onSubmit.bind(this);\n  }\n\n  // Wrap the onValidChange handler to set this.state.validates\n  onValidChange(name, isValid, wasValid) {\n    const { onValidChange } = this.props;\n    if (onValidChange) {\n      onValidChange(name, isValid, wasValid);\n    }\n\n    this.setState({ validates: isValid });\n  }\n\n  // Wrap the onSubmit handler to prevent submission if the form is invalid\n  onSubmit(e) {\n    const { onSubmit } = this.props;\n    if (onSubmit) {\n      onSubmit(e);\n    }\n\n    if (!this.state.validates) {\n      e.preventDefault();\n    }\n  }\n\n  // The form is invalid if there are any invalid items in its validation context\n  validate(valids) {\n    return Object.keys(valids).every(k =\u003e valids[k] !== false);\n  }\n\n  render() {\n    const { onSubmit, onValidChange, validate } = this;\n    const { children, name, ...formProps } = this.props;\n    delete formProps.onValidChange; // avoid passing down `onValidChange` from props\n\n    // Set up `form` props\n    Object.assign(formProps, { onSubmit, name });\n\n    // Render `form` and create validation context `Validate` (which is also validation context-aware)\n    return \u003cValidate validate={ validate } onValidChange={ onValidChange } name={ name }\u003e\n      \u003cform { ...formProps }\u003e\n        {children}\n      \u003c/form\u003e\n    \u003c/Validate\u003e;\n  }\n}\n\nForm.propTypes = {\n  name: string.isRequired, // Form identifier name\n  onSubmit: func, // onSubmit handler for form\n  onValidChange: func, // validity change handler\n  children: node // React children\n};\n```\n\n## Demo\n\nFor a more in-depth demonstration, see the example project under `demo/`.\n\n## License\n\n[MIT](LICENSE)\n\n[react-docs-context]: https://facebook.github.io/react/docs/context.html (React context API docs)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgodaddy%2Freact-validation-context","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgodaddy%2Freact-validation-context","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgodaddy%2Freact-validation-context/lists"}