mui-fields
Install
npm install --save mui-fieldsoryarn add mui-fields
Usage
settings: {fieldName: attributes}:
fieldName (string): Tên của trường.
attributes (object): thuộc tính của trường (extends tất cả thuộc tính của MUI TextField) // xem thêm https://material-ui.com/api/text-field/
useFormMethods:
các methods của useForm // xem ví dụ bên dưới
import React useState from 'react'import useForm from 'react-hook-form' import renderFields from 'mui-fields' { const formValues setFormValues = const methods = const _renderFieds = return const _onSubmit = data console return <form = => <div> <button =>Submit</button> </div> formValues && <pre>JSON</pre> </form> }
API
Default: type = 'text'
- isSelectBox (bool):
render box lựa chọn các giá trị của trường values
- select (bool):
render box lựa chọn các giá trị của trường values
- values (array):
các giá trị
(required
) - value (any):
giá trị hiện tại của box
- mapKey (func):
map giá trị cho key từ trường values
- mapValue (func):
map giá trị cho value từ trường values
- mapLabel (func):
map giá trị cho label từ trường values
- onChangeValue (func):
value => {/* tác vụ với giá trị mới (value)*/}
- values (array):
- isCheckBox (bool):
render check box
- check (bool):
render check box
- checkbox (bool):
render check box
- checked (bool):
giá trị hiện tại checked or unchecked
- onChangeChecked (func):
checked => {/* tác vụ với giá trị mới (checked)*/}
- checked (bool):
- isSwitch (bool)
- switch (bool)
- như isCheckBox
- isMultipleSelect (bool):
render multiple select
https://github.com/react-hook-form/react-hook-form
Xem thêm react-hook-form tạiLicense
MIT