mushan0x0 / rc-form-hooks

Use hooks to bind form components to actions such as uniform validation and get values.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

rc-form-hooks

Use hooks to bind form components to actions such as uniform validation and get values.

NPM JavaScript Style Guide

Install

npm install --save rc-form-hooks

or

yarn add rc-form-hooks

Usage

import React from 'react';
import useForm from 'rc-form-hooks';

export default () => {
  const { getFieldDecorator, validateFields, errors, values } = useForm<{
    username: string;
  }>();
  const handleSubmit = (e: React.FormEvent) => {
    e.preventDefault();
    validateFields()
      .then(console.log)
      .catch(e => console.error(e.message));
  };
  return (
    <form onSubmit={handleSubmit}>
      {getFieldDecorator('username', {
        rules: [{ required: true, message: 'Please input username!' }]
      })(<input type='text' />)}
      <span className={'value'}>{values.username}</span>
      <span className={'error'}>{errors.username.message}</span>
      <button type={'submit'}>submit</button>
    </form>
  );
};

License

MIT © mushan0x0

About

Use hooks to bind form components to actions such as uniform validation and get values.

License:MIT License


Languages

Language:TypeScript 93.7%Language:JavaScript 4.8%Language:HTML 1.2%Language:CSS 0.2%