Skip to main content

Error

Basics

The error component lets your form to display meaningful messages to the user when a form element doesn't satisfy its validation policy (here for validation info).

The whole logic is handled internally by Kingpin itself soo you don't have to manually show the error.

Props

NameMandatoryPurpose
nametrueThe name which points to the related input. The name has to follow the pattern: {componentName}:{error}
childrentrueThe JSX element to show.
import { Error, Form, Input } from 'kingpin-react-form'

const shouldNotBeEmpty = (s: string): boolean => s.length > 0

function App(): JSX.Element {
return (
<Form onSubmit={submit}>
<Input name="email" type="email" validation={shouldNotBeEmpty} />
<Error name="email:error">
<p>Email should not be empty.</p>
</Error>
<button type="submit">Submit</button>
</Form>
)
}

Validation solutions

The validation system offer many different ways to show the error messages. Check the documentation for more about error displaying.