{"id":16247858,"url":"https://github.com/jcblw/react-state-validation","last_synced_at":"2025-04-08T12:17:24.122Z","repository":{"id":57345302,"uuid":"48271218","full_name":"jcblw/react-state-validation","owner":"jcblw","description":"Validate react components state","archived":false,"fork":false,"pushed_at":"2017-05-12T14:22:16.000Z","size":7,"stargazers_count":0,"open_issues_count":2,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-14T08:16:47.357Z","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/jcblw.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":"2015-12-19T06:27:24.000Z","updated_at":"2015-12-19T06:27:45.000Z","dependencies_parsed_at":"2022-09-14T04:31:35.485Z","dependency_job_id":null,"html_url":"https://github.com/jcblw/react-state-validation","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcblw%2Freact-state-validation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcblw%2Freact-state-validation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcblw%2Freact-state-validation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcblw%2Freact-state-validation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jcblw","download_url":"https://codeload.github.com/jcblw/react-state-validation/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247838447,"owners_count":21004580,"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-10T14:39:02.909Z","updated_at":"2025-04-08T12:17:24.104Z","avatar_url":"https://github.com/jcblw.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# React State Validation\n\n[![Build Status](https://travis-ci.org/jcblw/react-state-validation.svg)](https://travis-ci.org/jcblw/react-state-validation)\n\nReact State Validation uses the propTypes validation pattern to validate states.\n\n## Usage\n\nThe `stateValidation` method can be used a decorator.\n\n```javascript\nimport React, {Component} from 'react'\nimport {stateValidation} from 'react-state-validation'\nconst stateValidations = {\n  customState: function(state, stateName, componentName) {\n    if (!/matchme/.test(state[stateName])) {\n      return new Error('Validation failed!');\n    }\n  }\n}\n\n\n@stateValidation\nclass App extends Component {\n  constructor () {\n    super()\n    this.state = {\n      customState: ''\n    }\n  }\n\n  render () {\n    // the stateValidation method will set the errors key will the current state errors\n    const {errors} = this.state\n    // the key of the state will be the same key in the errors object\n    const {customState} = errors\n    // if there is errors it will be an array of strings\n    // eg. ['Validation failed!']\n    //...\n  }\n}\n\nApp.stateValidations = stateValidations\n```\n\nor if your not using decorators you can just wrap the component with the stateValidation method.\n\n```javascript\nexport stateValidation(App)\n```\n\n## Contributing\n\nPlz do it! oh and run `npm test`. I use [standard](http://standardjs.com/) for code style/linting, and [ava](https://github.com/sindresorhus/ava) for testing.\n\n\n## Cool modules to use with this\n\n- [react-validator-prop-types](https://www.npmjs.com/package/react-validator-prop-types)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjcblw%2Freact-state-validation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjcblw%2Freact-state-validation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjcblw%2Freact-state-validation/lists"}