Introduction
Forms for React and Solid, with the form logic in one small core.
The core holds values, arrays, errors and submit state, and knows nothing about either framework. The adapter, @lunarhue/forms-react or @lunarhue/forms-solid, connects it to your components. A Vue adapter is planned.
Validation is built in. Undo, input masks, schema libraries and the rest are plugins, all imported from one plugins entry. Your bundle carries only the ones you import.
Field names are typed. The form’s value type comes from its starting values,
and every name you write is checked against it:
const signUp = createForms().define({
defaultValues: { name: "", email: "" },
onSubmit: (value) => save(value),
});
function SignUpForm() {
const form = createForm(signUp);
return (
<form.Form>
{(formProps) => (
<form {...formProps}>
<form.Field name="name">{(field) => <input {...inputProps(field)} />}</form.Field>
{/* Type error: "emial" is not a field of signUp. */}
<form.Field name="emial">{(field) => <input {...inputProps(field)} />}</form.Field>
</form>
)}
</form.Form>
);
}Where to go next
- Install the adapter.
- Build your first form. The Basics pages after it use no plugins.
- Make reusable field components once the forms repeat themselves.
- Add plugins for dirty tracking, undo, masks and the rest.
Last updated