A lightweight, zero-dependency React form state and validation library inspired by Angular Reactive Forms.
- ✅ Zero runtime dependencies
- ✅ Type-safe
- ✅ Composable validators
- ✅ Context-based architecture
- ✅ Tree-shakeable
- ✅ Lightweight & fast
npm i reactive-formifyimport React from "react";
import {
useForm,
FormProvider,
required,
minLength
} from "reactive-formify";
function MyForm() {
const form = useForm({
initialValues: {
name: "",
password: ""
}
});
return (
<FormProvider form={form}>
<form onSubmit={form.handleSubmit(console.log)}>
<input
value={form.values.name}
onChange={(e) => form.setValue("name", e.target.value)}
/>
{form.errors.name && <p>{form.errors.name}</p>}
<input
type="password"
value={form.values.password}
onChange={(e) => form.setValue("password", e.target.value)}
/>
{form.errors.password && <p>{form.errors.password}</p>}
<button type="submit">Submit</button>
</form>
</FormProvider>
);
}Built-in validators:
requiredminLengthmaxLengthpatternemailcomposeValidators
import { required, minLength } from "reactive-formify";
const nameValidator = composeValidators(
required("Name is required"),
minLength(3, "Minimum 3 characters")
);Creates and manages form state.
{
initialValues: Record<string, any>;
}{
values: FormValues;
errors: FormErrors;
touched: Record<string, boolean>;
setValue: (path: string, value: any) => void;
handleSubmit: (onValid: (values) => void) => (e) => void;
reset: () => void;
}Provides form instance through React context.
<FormProvider form={form}>
{children}
</FormProvider>Access form instance from nested components.
const form = useFormContext();import { composeValidators } from "reactive-formify";
const validator = composeValidators(
required(),
minLength(5)
);Validators return:
string | null
null→ validstring→ error message
This library was built to:
- Provide Angular Reactive Forms–like architecture in React
- Keep full control over state
- Avoid heavy abstraction layers
- Stay dependency-free
- Be fully TypeScript friendly
- Minimal API surface
- Maximum flexibility
- Composable architecture
- Predictable state updates
- Small bundle size
- Async validators
- FieldArray support
- Nested object support
- DevTools integration
- Performance optimizations
- Schema-based validation mode
Pull requests are welcome.
If you’d like to discuss major changes, open an issue first.
Omkar Joshi
GitHub: https://github.com/joshi-omkar