react-hook-form-antd
react-hook-form-antd copied to clipboard
๐๐ Master your Ant Design form with React Hook Form! ็จ React Hook Form ๆฟๆไฝ ็ Ant Design ่กจๅ๏ผ
๐ React Hook Form Antd ๐
Master your And Design form with React Hook Form!
English | ็ฎไฝไธญๆ
๐ Requirement
- react-hook-form
^7 - antd
^5
๐ถ 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:
- Use
useFormfromreact-hook-formand getcontrol - Use
FormItemfromreact-hook-form-antdinstead ofForm.Item- Pass
controlto allFormItem(Field names can be inferred bycontrol๐) - Remove
rulesand use react hook form resolver instead (You can use schema from any validation libraries ๐คฉ) - Use
handleSubmitinonFinish
- Pass
- Enjoy! ๐
๐น API
๐ FormItem
Ant Design
Form.ItemAPI
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 ๐ป ๐ค ๐ง ๐ |
Jakub Szewczyk ๐ป |
Dino Muharemagiฤ ๐ป ๐ |
avegatolber ๐ป ๐ |
This project follows the all-contributors specification. Contributions of any kind welcome!