2.0.7 • Published 3 years ago

form-handler-hook v2.0.7

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

Form Handler Hook v2

A hook to handle forms in React. This is a complete revamp of the previous versions.

Features

  • Provides validation (still in development, more will be available soon)
  • Provides excellent type-intelliscence
  • Returns form handler functions (like handleChange and handleSubmit), along with shorthands for input-element props (inputProps)

Usage

function MyComponent() {
  const { handleSubmit, inputProps, errors } = useForm({
    values: {
      email: "",
      password: "",
    },
    validation: {
      email: {
        isRequired: true,
      },
      password: {
        isRequired: true,
        minLength: 10,
        shouldContain: /[0-9][a-z]/g,
      },
    },
    onSubmit: (values, { addError }) => {
      // ..
    },
  });

  return (
    <form onSubmit={handleSubmit}>
      <input type="email" {...inputProps("email")} />
      <input type="password" {...inputProps("password")} />
      <button type="submit">Submit</button>
    </form>
  );
}
2.0.7

3 years ago

2.0.6

3 years ago

2.0.3

3 years ago

2.0.5

3 years ago

2.0.4

3 years ago

2.0.2

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago