Unform
Accessing form reference
Accessing form reference
Unform exposes various helper functions through the form ref.
1export default function MyForm() {2 const formRef = useRef(null)34 // Use formRef.current to access all methods56 return <Form ref={formRef}>...</Form>7}
Methods
Function | Description |
---|---|
submitForm() | Trigger onSubmit function |
reset(data?: object) | Reset (and maybe replace) all form data |
getData() | Returns all form data |
setData(data: object) | Set multiple fields data |
getErrors() | Returns all field errors |
setErrors(errors: object) | Set multiple field errors |
clearField(fieldName: string) | Clear single field value |
getFieldValue(fieldName: string) | Get single field value |
setFieldValue(fieldName: string, value: string) | Set single field value |
getFieldError(fieldName: string) | Get single field error |
setFieldError(fieldName: string, error: string) | Set single field error |
getFieldRef(fieldName: string) | Get single field reference |