Skip to Content
Piplup
@piplup/rhf-coreComponents

FormErrorProvider

Provider component from @piplup/rhf-core that centralizes form error handling and mapping for friendly error messages.

Import

import { FormErrorProvider } from '@piplup/rhf-core';

Usage

Wrap your form with FormErrorProvider. Provide an errorParser function to translate raw error objects into user-friendly messages, or rely on default behavior.

'use client';import { HtmlFormHelperTextElement, HtmlInputElement } from '@piplup/rhf-adapters/html';import { FormErrorProvider } from '@piplup/rhf-core';import { useForm } from 'react-hook-form';export default function Page() {  const { control, handleSubmit } = useForm();  return (    <FormErrorProvider      errorParser={(error) => {        const message = error?.message;        if (typeof message === 'string') {          switch (message) {            case 'message.field.required':              return 'This field is required';            default:              return message;          }        }        return null;      }}    >      <form        onSubmit={handleSubmit((data) => {          alert(JSON.stringify(data, null, 2));        })}        noValidate      >        <div>          <HtmlInputElement            messages={{              required: 'message.field.required',            }}            className="border px-2 rounded"            control={control}            name="message"            required          />          <HtmlFormHelperTextElement            style={({ error }) => ({              ...(error && { color: 'red' }),            })}            control={control}            name="message"            renderOnError          />        </div>        <button          className="bg-black hover:bg-black/90 px-4 py-1 text-white rounded mt-3"          type="submit"        >          Submit        </button>      </form>    </FormErrorProvider>  );}

Props

Prop

Type

Patterns

  • Global mapping: Use a single errorParser at the app root to ensure consistent copy and localization.
  • Field-level overrides: Components can still render custom error messages when they need special phrasing.
  • i18n: Combine errorParser with your localization system to return translated messages.

Notes

  • FormErrorProvider does not replace form validation — it only maps and exposes error messages for rendering.
  • FormContainer is pre-configured with FormErrorProvider, so you can directly use errorParser prop without wrapping with another FormErrorProvider.

On this page