Getting Started
Installation
Install yet-another-form using your preferred package manager:
bash
npm install yet-another-formbash
yarn add yet-another-formbash
pnpm add yet-another-formYour First Form
The simplest way to create a form is to use the useForm hook:
jsx
import { useForm } from 'yet-another-form/react'
function MyForm() {
const { Form, setValue, values } = useForm({
onSubmit: (values) => {
console.log('Form submitted:', values)
},
})
return (
<Form>
<input name="name" onChange={setValue} value={values.name || ''} />
<input name="email" onChange={setValue} value={values.email || ''} />
<button type="submit">Submit</button>
</Form>
)
}How it Works
- Create the form -
useForm()returns everything you need to manage form state - Wrap your form - Use the
<Form>component to provide context - Connect inputs - Use
setValuefor onChange andvaluesto display current values - Handle submission - Pass
onSubmitto the hook configuration
What You Get
The useForm hook returns:
Form- A component that wraps your form elementsvalues- Current form values as an objectsetValue- Function to update field valuessetError- Function to set validation errorssetTouched- Function to mark fields as touchedisDirty- Boolean indicating if any field changedisValid- Boolean indicating if form has no errorsisSubmitting- Boolean indicating submission state
Next Steps
Now that you have a basic form working, you can:
- Add validation to your forms
- Learn about form submission handling
- Explore the API reference
- Check out more examples
