Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alanleite/react-schema-validator
Schema validator for using with react hooks and tree shaking in mind. (poc stage)
https://github.com/alanleite/react-schema-validator
hooks-api-react reactjs validator
Last synced: 9 days ago
JSON representation
Schema validator for using with react hooks and tree shaking in mind. (poc stage)
- Host: GitHub
- URL: https://github.com/alanleite/react-schema-validator
- Owner: alanleite
- License: mit
- Created: 2019-04-04T16:02:58.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-04T02:34:27.000Z (almost 2 years ago)
- Last Synced: 2023-08-24T06:33:40.820Z (about 1 year ago)
- Topics: hooks-api-react, reactjs, validator
- Language: JavaScript
- Homepage:
- Size: 1.15 MB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 17
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# react-schema-validator
A json schema validator made for react hooks.
WARNING: this library is in a very beginning and may have changes.
## Usage
```js
import { useStateWithValidator, schema } from 'react-schema-validator'const Errors = (errors, key) => (
if(!errors || errors[key]) { return [] }
return (
{errors[key].map((error, i) => (
{error}
))}
)
)const MyForm = () => {
const [state, setState] = useStateWithValidator({}, {
name: schema.text().required().min(1).max(10),
lastname: schema.text().min(1).max(20),
age: schema.number().min(18).max(80)
})const onChange = (e) => (
setState({
...state,
[e.name]: e.value
})
)return (
)
}
```## Roadmap
- [ ] Add more validation models
- [ ] Tree shaking compatibilities
- [ ] List of supported browsers
- [ ] Create tests and coverage### Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.