form-handler-hook
TypeScript icon, indicating that this package has built-in type declarations

2.0.7 • Public • Published

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>
  );
}

Readme

Keywords

none

Package Sidebar

Install

npm i form-handler-hook

Weekly Downloads

4

Version

2.0.7

License

MIT

Unpacked Size

27.9 kB

Total Files

8

Last publish

Collaborators

  • theruler007