Π€ΠΎΡΠΌΠ° Π·Π° ΠΌΠΈΠ½ΡΡΡ
import { createForm, type FormModel } from '@reformer/core';
import { useFormBundle } from '@reformer/core/react';
import { defineValidation, validate } from '@reformer/core/validation';
import { required, email } from '@reformer/core/validators';
import { FormField, Input, Button } from '@reformer/ui-kit';
type Contact = { email: string };
// 1. Π‘Ρ
Π΅ΠΌΠ° β ΠΏΡΠΈΠ²ΡΠ·ΠΊΠ° ΠΏΠΎΠ»Ρ ΠΊ ΡΠΈΠ³Π½Π°Π»Ρ ΠΌΠΎΠ΄Π΅Π»ΠΈ + ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ (Π±Π΅Π· Π²Π°Π»ΠΈΠ΄Π°ΡΠΎΡΠΎΠ²)
const schema = (model: FormModel<Contact>) => ({
children: [
{ model: model.$.email, component: Input, componentProps: { label: 'Email', type: 'email' } },
],
});
// 2. ΠΠ°Π»ΠΈΠ΄Π°ΡΠΈΡ β ΠΎΡΠ΄Π΅Π»ΡΠ½ΡΠΉ ΡΠ»ΠΎΠΉ
const validation = defineValidation<Contact>(({ model }) => {
validate(model.$.email, [required(), email()]);
});
function ContactForm() {
// 3. Π‘Π±ΠΎΡΠΊΠ° ΠΎΠ΄ΠΈΠ½ ΡΠ°Π·: ΠΌΠΎΠ΄Π΅Π»Ρ ΠΈΠ· initial, ΡΠ·Π»Ρ ΡΠΎΡΠΌΡ ΠΏΠΎΠ²Π΅ΡΡ
Π΅Ρ ΡΠΈΠ³Π½Π°Π»ΠΎΠ², ΠΏΡΠ°Π²ΠΈΠ»Π°
const bundle = useFormBundle(() =>
createForm<Contact>({ initial: { email: '' }, schema, validation })
);
// 4. ΠΡΠΏΡΠ°Π²ΠΊΠ° β ΠΎΠ΄ΠΈΠ½ ΠΏΡΠΎΠ³ΠΎΠ½ ΠΏΡΠ°Π²ΠΈΠ»; ΠΏΡΠΈ Π·Π°ΠΌΠ΅ΡΠ°Π½ΠΈΡΡ
ΠΎΠ±ΡΠ°Π±ΠΎΡΡΠΈΠΊ Π½Π΅ Π²ΡΠ·ΡΠ²Π°Π΅ΡΡΡ, ΠΏΠΎΠ»Ρ ΠΏΠΎΠ΄ΡΠ²Π΅ΡΠ΅Π½Ρ
const onSubmit = (event) => {
event.preventDefault();
void bundle.submission.submit((values) => console.log(values));
};
// 5. Π’ΠΎΠ½ΠΊΠΈΠΉ JSX β FormField Π΄Π΅Π»Π°Π΅Ρ Π²ΡΡ ΡΠ°Π±ΠΎΡΡ
return (
<form onSubmit={onSubmit}>
<FormField control={bundle.form.email} />
<Button type="submit">ΠΡΠΏΡΠ°Π²ΠΈΡΡ</Button>
</form>
);
}
Reactive by Design
Built on Preact Signals for fine-grained reactivity. Only components using changed values re-render.
Type-Safe Forms
Full TypeScript support with automatic type inference. Catch errors at compile time, not runtime.
Declarative Validation
14 built-in validators, async validation, and easy custom validators. Define validation rules once, apply everywhere.
Smart Behaviors
Computed fields, conditional visibility, field synchronization. Complex form logic made simple.
Nested Structures
Support for deeply nested objects and dynamic arrays. Build any form structure you need.
Framework Agnostic
Core library works anywhere. React bindings included, with more frameworks coming soon.
AI-Friendly
Well-documented API with clear patterns. AI assistants can easily understand and generate code using ReFormer.