rc-form-hooks
v1.0.1
Published
Use hooks to bind form components to actions such as uniform validation and get values.
Downloads
952
Readme
rc-form-hooks
Use hooks to bind form components to actions such as uniform validation and get values.
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