useFieldErrorMessage()
Allows you to get and set error messages for any field.
This hook is commonly used when creating custom error message components that display more than a single error message.
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.
setErrorMessages
Function which sets error messages for this field.
When to use?
At the moment, OneForm doesn't allow you to render or not render a field based on its error messages. So for now, this hook is required for those use cases.
Displaying multiple error messages
Another common use case would be creating your own <FieldErrorMessages />
component which displays more than a single field error.
OneForm doesn't natively have a component for this because it has no clue how to style your error messages. For example, the <FieldErrorMessage />
component only returns text.
Last updated