useFieldData()

A grab-all of helper values and functions to perform whatever actions you need.

If you're wanting to do something custom, you're in the right place. This is the simplest hook to use and is a great starting point.

You may wish to use useFieldValue or useFieldErrorMessages for better performance depending on your needs.

Like React's useContexthook, this hook forces your component to update anytime the value, visitation, or error messages update on a field.

Props

Props in

Prop Name

Description

name

The base field name without a /.

Props out

Prop Name

Description

errorMessages

Array of error message strings.

When changed, this value is updated.

fieldName

The OneForm field name with a /

isVisited

Boolean value representing the field's visited state.

register

Function which registers your component.

It returns an unregister function. Remember to clean when you're done.

setErrorMessages

Function which sets error messages for this field.

setValue

Function which sets the value for this field.

setVisited

Function which sets the field as visited.

You cannot unvisit a field.

value

Current field value. When changed, value is updated.

When to use?

Whenever you want to do something custom in OneForm related to a field, this hook is important.

OneForm handles a ton of state for you, so hooks like this aren't required.

If you can find a good use case for this hook, contact us so we can update the docs.

Creating a custom field component

If you want to create a custom <Field /> component, look at useField instead:

useField()

Last updated