Unform

Accessing field ref

Accessing field ref

To access a single field reference, you can use the getFieldRef function exposed inside the form ref.

1export default function MyForm() {
2 const formRef = useRef(null)
3
4 function focusNameInput() {
5 const nameInput = formRef.current.getFieldRef('name')
6
7 nameInput.focus()
8 }
9
10 return (
11 <Form ref={formRef}>
12 <Input name="name" />
13 </Form>
14 )
15}
Edit this page on GitHub