MCPcopy Index your code
hub / github.com/react-hook-form/error-message

github.com/react-hook-form/error-message @v2.0.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release v2.0.1 ↗ · + Follow
2 symbols 8 edges 7 files 0 documented · 0% 9 cross-repo links updated 17mo agov2.0.0 · 2021-04-09★ 3487 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README
    <a href="https://react-hook-form.com" title="React Hook Form - Simple React forms validation">
        <img src="https://raw.githubusercontent.com/bluebill1049/react-hook-form/master/docs/logo.png" alt="React Hook Form Logo - React hook custom hook for form validation" />
    </a>

Performant, flexible and extensible forms with easy to use validation.

npm downloads npm npm

Goal

A simple component to render associated input's error message.

Install

$ npm install @hookform/error-message

Quickstart

  • Single Error Message
import React from 'react';
import { useForm } from 'react-hook-form';
import { ErrorMessage } from '@hookform/error-message';

export default function App() {
  const { register, formState: { errors }, handleSubmit } = useForm();
  const onSubmit = (data) => console.log(data);

  return (
    <form onSubmit={handleSubmit(onSubmit)}>
      <input
        name="singleErrorInput"
        ref={register({ required: 'This is required.' })}
      />
      <ErrorMessage errors={errors} name="singleErrorInput" />

      <ErrorMessage
        errors={errors}
        name="singleErrorInput"
        render={({ message }) => 

{message}

}
      />

      <input name="name" ref={register({ required: true })} />
      <ErrorMessage errors={errors} name="name" message="This is required" />

      <input type="submit" />
    </form>
  );
}

  • Multiple Error Messages
import React from 'react';
import { useForm } from 'react-hook-form';
import { ErrorMessage } from '@hookform/error-message';

export default function App() {
  const { register, formState: { errors }, handleSubmit } = useForm({
    criteriaMode: 'all',
  });
  const onSubmit = (data) => console.log(data);

  return (
    <form onSubmit={handleSubmit(onSubmit)}>
      <input
        name="multipleErrorInput"
        ref={register({
          required: 'This is required.',
          pattern: {
            value: /d+/,
            message: 'This input is number only.',
          },
          maxLength: {
            value: 10,
            message: 'This input exceed maxLength.',
          },
        })}
      />
      <ErrorMessage
        errors={errors}
        name="multipleErrorInput"
        render={({ messages }) =>
          messages &&
          Object.entries(messages).map(([type, message]) => (


{message}


          ))
        }
      />

      <input type="submit" />
    </form>
  );
}

API

Prop Type Required Description
name string Associated field name.
errors object errors object from React Hook Form. It's optional if you are using FormProvider.
message string \| React.ReactElement inline error message.
as string \| React.ReactElement \| React.ComponentType Wrapper component or HTML tag. eg: as="p", `as={

}oras={CustomComponent}. This prop is incompatible with proprenderand will take precedence over it. | |render|Function` | | This is a render prop for rendering error message or messages.

Note: you need to set criteriaMode to all for using messages. |

Backers

Thank goes to all our backers! [Become a backer].

Contributors

Thanks goes to these wonderful people. [Become a contributor].

Core symbols most depended-on inside this repo

ErrorMessage
called by 0
src/ErrorMessage.tsx

Shape

Function 2

Languages

TypeScript100%

Modules by API surface

src/ErrorMessage.tsx1 symbols
src/ErrorMessage.test.tsx1 symbols

For agents

$ claude mcp add error-message \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page