npm install @alepha/react
React hooks for managing forms in Alepha applications.
This module provides a set of hooks to simplify form handling, validation, and submission in React applications built with Alepha.
It includes:
useForm: A hook for managing form state, validation, and submission.Hooks provide a way to tap into various lifecycle events and extend functionality. They follow the convention of starting with use and return configured hook instances.
Custom hook to create a form with validation and field management. This hook uses TypeBox schemas to define the structure and validation rules for the form. It provides a way to handle form submission, field creation, and value management.
1import { t } from "alepha"; 2 3const form = useForm({ 4 schema: t.object({ 5 username: t.text(), 6 password: t.text(), 7 }), 8 handler: (values) => { 9 console.log("Form submitted with values:", values);10 },11});12 13return (14 <form {...form.props}>15 <input {...form.input.username.props} />16 <input {...form.input.password.props} />17 <button type="submit">Submit</button>18 </form>19);