1.1.0 โ€ข Published 2 months ago

react-hook-form-antd v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

๐Ÿ“‹ React Hook Form Antd ๐Ÿœ

Master your And Design form with React Hook Form!

version license size downloads

English | ็ฎ€ไฝ“ไธญๆ–‡

๐Ÿ“œ Requirement

๐Ÿ•ถ Example

EXAMPLE

๐Ÿ“ฆ Installation

npm install react-hook-form-antd

๐ŸŽฏ Quickstart

You may have an original antd form like below

<Form onFinish={onFinish}>
	<Form.Item
		label="Username"
		name="username"
		rules={[
			{ required: true, message: 'Required' },
			{ max: 15, message: 'Username should be less than 15 characters' },
		]}
	>
		<Input />
	</Form.Item>
	<Form.Item
		label="Password"
		name="password"
		rules={[{ required: true, message: 'Required' }]}
	>
		<Input.Password />
	</Form.Item>
	<Form.Item name="remember" valuePropName="checked">
		<Checkbox>Remember me</Checkbox>
	</Form.Item>
	<Form.Item>
		<Button type="primary" htmlType="submit">
			Submit
		</Button>
	</Form.Item>
</Form>

Check the EXAMPLE for this form after using react-hook-form-antd!

All you need to do:

  1. Use useForm from react-hook-form and get control
  2. Use FormItem from react-hook-form-antd instead of Form.Item
    • Pass control to all FormItem (Field names can be inferred by control ๐Ÿ˜Ž)
    • Remove rules and use react hook form resolver instead (You can use schema from any validation libraries ๐Ÿคฉ)
    • Use handleSubmit in onFinish
  3. Enjoy! ๐ŸŽ‰

๐Ÿ•น API

๐Ÿ”— FormItem

Ant Design Form.Item API

A component instead of Form.Item in antd. It has inherited all props from Form.Item except rules validateStatus (If you need rules, please use react hook form resolver instead)

Added and modified props:

PropTypeDescription
controlControlcontrol object from useForm
namestringform field name

๐Ÿ‘ฅ Contributors

Thanks goes to these wonderful people (emoji key):

This project follows the all-contributors specification. Contributions of any kind welcome!

1.1.0

2 months ago

1.1.0-beta.0

2 months ago

1.0.1

6 months ago

1.0.0

6 months ago

0.0.3

6 months ago

0.0.2

1 year ago

0.0.1

1 year ago