Unform

Accessing form reference

Table of Contents

Unform exposes a various helper functions through the form reference.

1export default function MyForm() {
2 const formRef = useRef(null);
3
4 // Use formRef.current to access all methods
5
6 return <Form ref={formRef}>...</Form>;
7}

Methods

FunctionDescription
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
Edit this page on GitHub