Form & Validation

useForm

Comprehensive form state management with validation, submission, and error handling.

import { useForm } from "saha-ui"

Uses

Full-featured form state manager: values, touched, errors, field helpers, and validation integration.

Props

NameTypeDescriptionDefault
initialValuesobjectInitial form values.-
validationRulesRecord<string, (value: any) => string | undefined>Optional per-field validation functions.-

Returns

NameDescription
[formState, actions]formState maps field keys to { value, error, touched }.
actionsHelpers: setValue, setError, setTouched, handleChange, handleBlur, validate, validateField, reset, setValues.

Example

const [form, { handleChange, handleBlur, validate }] = useForm({ email: '', password: '' }, { email: (v) => !v ? 'Required' : undefined });

Notes

Validation rules are user-provided functions that return error messages or undefined.
Saha UI - The Modern React Component Library