Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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)

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.