iusehooks / usetheform

React library for composing declarative forms, manage their state, handling their validation and much more.
https://iusehooks.github.io/usetheform/
MIT License
86 stars 33 forks source link

Enabling sync and async validation at form level #29

Closed antoniopangallo closed 3 years ago

antoniopangallo commented 3 years ago

Improvement:

Example:

 const graterThan10 = ({ values }) =>
    values && values['A'] + values['B'] > 10 ? undefined : 'A+B must be > 10'

function App() {
  const [status, validation] = useValidation([graterThan10])
  return (
    <Form touched {...validation}>
      <Collection object name="values">
        <Input type="number" name="A" value="1" />
        <Input type="number" name="B" value="2" />
      </Collection>
      {status.error && <label>{status.error}</label>}
      <button type="submit">Press to see results</button>
    </Form>
  );
}