react-use-former

0.0.3 • Public • Published

useForm hook for React

Install it with yarn:

yarn add react-use-former

Or with npm:

npm i react-use-former --save

Demo

The simplest way to start playing around with react-use-former is with this CodeSandbox snippet: https://codesandbox.io/s/ym9zlov3nj

import React, { useState } from 'react';
import useForm from 'react-use-form';

export default function MyComponent() {
  const [Form, formData, serializeFormData] = useForm();

  const { isValid } = formData;
  return (
    <div>
      <Form
        onSubmit={(e) => {
          e.preventDefault();
          console.log(serializeFormData());
        }}
      >
        <input type="text" name="field1" validation={['required']} />
        <input type="text" name="field2" validation={['number']} />
        <button type="submit" disabled={!isValid}>
          SUBMIT
        </button>
      </Form>
    </div>
  );
}

Package Sidebar

Install

npm i react-use-former

Weekly Downloads

2

Version

0.0.3

License

MIT

Unpacked Size

11.1 kB

Total Files

8

Last publish

Collaborators

  • eskydar