MinForms

:fire: Small and quick alternative to formik
Why
Formik is a really great library for fast building forms in Typescript React. Has simply API
and it's easy to use. MinForms library is not trying to replace Formik in any
way, it's just a small lib which helps you to build basic forms faster. For complex
forms, I suggest you to use formik instead.
Main features:
- small in size
- easy to use (only one component)
- has full
typescript
support - no external dependencies
! minforms
library is designed to provides no Fields or Custom Inputs. It only cares
about values you provided, so you can build best suited Fields/Inputs for you.
Installation
npm i minforms
or yarn i minforms
Examples
Building basic Login form
import * as React from "react";
import { MinForm } from "../lib/index";
export const MyForm = (props: { email: string; password: string }) => (
<MinForm
initialValues={{ email: props.email, password: props.password }}
render={({ values }) => (
<form>
<h2>Login Page</h2>
<input type="text" value={values.email} />
<br />
<input type="password" value={values.password} />
<br />
</form>
)}
/>
);
More examples can be found in ./examples/
API
Minforms
export type MinFormsProps<V extends object> = {
initialValues: V;
values?: Partial<V>;
render: (props: RenderProps<V>) => JSX.Element | JSX.Element[];
validation?: (values: V) => ErrorsFromValues<V>;
validateOnSubmit?: boolean;
validateOnInit?: boolean;
onValuesChange?: (values: V, nextValues: Partial<V>) => Partial<V>;
};
Minforms Render
export type RenderProps<V extends object> = {
values: V;
handleChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
errors: ErrorsFromValues<V>;
setValue: SetValue<V>;
submit: (callback: (values: V) => void) => void;
};