Progressively enhance HTML forms with React. Build resilient, type-safe forms with no hassle using web standards.
CONFORM is a form validation library designed for use with the Remix and React Router frameworks. It utilizes a progressive enhancement approach and offers several features to simplify the validation process. This library provides automatic type coercion, simplified integration through event delegation, field name inference, focus management, and accessibility support. CONFORM is lightweight, with a compressed size of approximately 5kb.
To install CONFORM, follow these steps:
npm install conform
import { useForm, useField } from 'conform';
export function MyForm() {
const { handleSubmit, values, errors } = useForm({
// Define your validation schema and rules
validation: {
email: {
required: true,
email: true,
},
password: {
required: true,
minLength: 8,
},
},
onSubmit: async (values) => {
// Handle form submission logic
},
});
const emailField = useField('email');
const passwordField = useField('password');
return (
<form onSubmit={handleSubmit}>
<label>
Email:
<input {...emailField} />
{errors.email && <p>{errors.email}</p>}
</label>
<label>
Password:
<input {...passwordField} type="password" />
{errors.password && <p>{errors.password}</p>}
</label>
<button type="submit">Submit</button>
</form>
);
}
CONFORM is a powerful form validation library that prioritizes progressive enhancement, automatic type coercion, simplified integration, field name inference, focus management, and accessibility support. With a minimal file size and an easy-to-use API, CONFORM enables developers to enhance their forms with robust validation capabilities while ensuring an inclusive user experience.