0.0.3 • Published 5 years ago

@mozisan/react-form v0.0.3

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

@mozisan/react-form

Installation

$ npm install -S @mozisan/react-form
$ yarn add @mozisan/react-form

Basic usage

import {
  boolean,
  number,
  string,
  useForm,
} from '@mozisan/react-form';
import React from 'react';

export const RegistrationForm: React.FC = () => {
  const { field, handleSubmit } = useForm({
    fields: {
      name: string(),
      age: number(),
      acceptsPolicy: boolean(),
    },
  });

  return (
    <form onSubmit={handleSubmit((data) => { ... })}>
      <div>
        <input ref={field('name')} type="text" />
      </div>

      <div>
        <input ref={field('age')} type="number" />
      </div>

      <div>
        <input ref={field('acceptsPolicy')} type="checkbox" />
      </div>

      <button type="submit">Submit</button>
    </form>
  );
};