@comparaonline/ui-form-errors
v3.70.0
Published
## Installation
Downloads
530
Maintainers
Keywords
Readme
@comparaonline/ui-form-errors
Installation
yarn add @comparaonline/ui-form-errors
Usage
This package exposes a ErrorMessages
context using ErrorMessageProvider
and
ErrorMessagesConsumer
. A utility called replacer
can be used to use templates that follow this convention
'The min value is {{minValue}} and the maxValue is {{maxValue}}'
... in your ErrorMessagesConsumer
.
ErrorMessagesProvider
import { ErrorMessagesProvider } from '@comparaonline/ui-form-errors';
interface ErrorMessages = {
[errorCode: string]: string
}
const errorMessages: ErrorMessages = {
required: 'This field is required',
outOfRange: 'The min value is {{minValue}} and the maxValue is {{maxValue}}'
}
<ErrorMessagesProvider value={{ errorMessages }}>
...
</ErrorMessagesProvider>
ErrorMessagesConsumer
<ErrorMessagesConsumer>
{({ errorMessages }) => ()}
</ErrorMessagesConsumer>