Skip to main content

ReFormer

Reactive forms library with signals

МодСль Π½Π° сигналах β€” источник истины. Одна схСма связываСт поля, Π²Π°Π»ΠΈΠ΄Π°Ρ†ΠΈΡŽ ΠΈ Ρ€Π΅Π°ΠΊΡ‚ΠΈΠ²Π½Ρ‹Π΅ behaviors. Π Π΅Π½Π΄Π΅Ρ€ΠΈΡ‚Π΅ Π²Ρ€ΡƒΡ‡Π½ΡƒΡŽ, ΠΈΠ· схСмы ΠΈΠ»ΠΈ ΠΈΠ· JSON.

Π€ΠΎΡ€ΠΌΠ° Π·Π° ΠΌΠΈΠ½ΡƒΡ‚Ρƒ

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.