react-hook-form-antd
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

📋 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

Show code
<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:

Prop Type Description
control Control control object from useForm
name string form field name

👥 Contributors

Thanks goes to these wonderful people (emoji key):

Yeyang (Justin) Sun
Yeyang (Justin) Sun

💻 🤔 🚧 📖
Jakub Szewczyk
Jakub Szewczyk

💻
Dino Muharemagić
Dino Muharemagić

💻 🐛
avegatolber
avegatolber

💻 🐛

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

Package Sidebar

Install

npm i react-hook-form-antd

Weekly Downloads

1,358

Version

1.1.0

License

MIT

Unpacked Size

15.7 kB

Total Files

6

Last publish

Collaborators

  • jsun969