![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
@hookform/error-message
Advanced tools
Performant, flexible and extensible forms with easy to use validation.
A simple component to render associated input's error message.
$ npm install @hookform/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 }) => <p>{message}</p>}
/>
<input name="name" ref={register({ required: true })} />
<ErrorMessage errors={errors} name="name" message="This is required" />
<input type="submit" />
</form>
);
}
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]) => (
<p key={type}>{message}</p>
))
}
/>
<input type="submit" />
</form>
);
}
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={<p />} or as={CustomComponent} . This prop is incompatible with prop render and 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. |
Thank goes to all our backers! [Become a backer].
Thanks goes to these wonderful people. [Become a contributor].
FAQs
React Hook Form error message component
We found that @hookform/error-message demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.