@usevyre/react@usevyre/vue

Form

A controlled, data-driven form with zero dependencies. Declare validation rules per field; errors map into the wrapped Fieldautomatically. Validates on submit and — after the first submit — live on blur and change.


Sign-up form with validation

Submit with empty or invalid fields to see errors appear inline, then correct them and watch the errors clear live. The confirm field uses a custom cross-field validate rule.

At least 8 characters
import { useState } from "react";
import { Form, FormField, Input, Button, Stack } from "@usevyre/react";

const [values, setValues] = useState({ email: "", password: "", confirm: "" });

<Form values={values} onChange={setValues} onSubmit={() => save(values)}>
  <FormField name="email" label="Email" rules={{ required: true, email: true }}>
    <Input type="email" placeholder="you@example.com" />
  </FormField>
  <FormField
    name="password"
    label="Password"
    hint="At least 8 characters"
    rules={{ required: true, minLength: 8 }}
  >
    <Input type="password" placeholder="••••••••" />
  </FormField>
  <FormField
    name="confirm"
    label="Confirm password"
    rules={{
      required: true,
      validate: (v, all) =>
        v === all.password ? null : "Passwords do not match",
    }}
  >
    <Input type="password" placeholder="••••••••" />
  </FormField>
  <Stack direction="row" gap="sm" justify="end">
    <Button type="submit" variant="primary">Create account</Button>
  </Stack>
</Form>

Form props

Props

PropTypeDefaultDescription
valuesRecord<string, any>Controlled values map. Omit for uncontrolled.
defaultValuesRecord<string, any>{}Initial values when uncontrolled.
onChange(values) => voidFires whenever any field value changes.
onSubmit(values) => void | PromiseFires on submit ONLY when the form is valid.
onInvalid(errors) => voidFires on submit when validation fails.
classstringAdditional CSS class.

FormField props

Wrap a single control. FormField injectsname/value/onChange/onBlurand renders it inside a Field with the right label and error state.

Props

PropTypeDefaultDescription
namestringKey into the form's values map (required).
labelstringLabel rendered by the wrapping Field.
hintstringHelper text shown when there is no error.
rulesobjectrequired | minLength | maxLength | min | max | pattern (RegExp) | email | validate(value, allValues) => string | null.
Zero dependencies. Validation is built in — no zod/yup needed. For anything custom, rules.validate(value, allValues)returns an error string or null.