A headless react hook for forms.
npm install use-headless-formA typesafe headless react hook for forms.
npm install use-headless-form
``tsx
const Form = () => {
const validation = useHeadlessForm({
username: {
defaultValue: "",
validators: [
(value) =>
(value.length < 2 || value.length > 50) &&
"Username must be between 2-50 characters.",
],
transformer: (value) => value.trim(),
},
password: {
defaultValue: "",
validators: [
(value) => value.length === 0 && Password cannot be empty.,
(value) =>
value.length < 8 && "Password needs to be atleast 8 characters long.",
(value) =>
value.length > 250 && "Password cannot be more than 250 characters.",
],
},
passwordAgain: {
defaultValue: "",
validators: [
(value, { password }) =>
value !== password.value && "Passwords do not match",
],
},
});
return (
const FormErrors = ({ errors }: { errors: React.ReactNode[] }) => (