Lightweight React Form Utility Library – useForm

Description:

useForm is a lightweight, flexible, customizable form utility library for React.

Installation:

# Yarn
$ yarn add @rvision/use-form
# NPM
$ npm i @rvision/use-form

Basic usage:

const defaultValues = {
  firstName: '',
  lastName: '',
  email: '',
  agree: false
};
const Form = () => {
  const {
    register,
    handleSubmit,
  } = useForm({
    defaultValues
  });
  const onSubmit = values => console.log(values);
  return (
    <div>
        <label>
          Enter first name:
          <input type="text" {...register('firstName')} />
        </label>
        <label>
          Enter last name:
          <input type="text" {...register('lastName')} />
        </label>
        <label>
          Enter email:
          <input type="email" {...register('email')} />
        </label>
        <label>
          <input type="checkbox" {...register('agree')} />
          I agree to terms and conditions
        </label>
        <button type="submit" onClick={handleSubmit(onSubmit)}>
          Register
        </button>
    </div>
  );
}

Preview:

Lightweight React Form Utility Library - useForm

Add Comment