<IfFieldErrorMessage>

This component allows you to conditionally render based on the existence of a field error message.

Props

import {
  FieldErrorMessage,
  IfFieldErrorMessage,
  OneForm,
} from '@oneform/react'

const ConditionalFieldErrorMessageExample = () => (
  <OneForm
    errorMessages={{
      firstName: ['You need a name'],
    }}
  >
    <div>
      <IfFieldErrorMessage name="firstName">
        <small>
          <FieldErrorMessage name="firstName" />
        </small>
      </IfFieldErrorMessage >
    </div>
  </OneForm>
)

export default ConditionalFieldErrorMessageExample 

When to use?

This component will probably be used often if you have separate error components.

Some notable uses:

  • You want to show a <FieldErrorMessage>, but have it wrapped in some styled elements, so you only want to show it when an error message exists.

  • You want to show instructions when a field has errored.

Last updated