import React from 'react' import ReactDOM from 'react-dom' import { useForm } from '../' const TextError: React.FC<{ error?: string }> = ({ error }) => (!error ? null :
{error}
) const initial = { username: '', password: '', type: 'formhero', awesome: true, } const Index: React.FC = () => { const { field, form, errors, isValid, setForm, setErrors, setField } = useForm(initial, { username: [ /^abc/, { validator: async (s: string) => { return true }, message: 'Async shit not working', }, (s: string) => (s.includes('d') ? true : 'Needs the D'), ], password: { validator: /^.{3,}$/, message: 'To short', }, awesome: value => !!value, }) const _submit = (e: React.FormEvent) => { e.preventDefault() console.log(form, errors, isValid) } const reset = () => { setForm(initial) setField('username', 'asdf') } const error = () => { setErrors({ username: 'nope', }) } return (
Username


Password


Which one to choose?








) } ReactDOM.render(, document.getElementById('root'))