
Product
Announcing Socket Fix 2.0
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
@avinlab/react-form
Advanced tools
A React library for building forms with ease, providing hooks for managing form state and validation in React applications.
A React library for building forms with ease, providing hooks for managing form state and validation in React applications.
npm install @avinlab/react-form
Online example is here
Create form with validation:
import React from 'react';
import { useForm, useFormValidation, useFormWatch } from '@avinlab/react-form';
const ExampleForm = () => {
const form = useForm({ name: 'Bob', age: 20 });
const { errors, isValid, validate } = useFormValidation(form, (values, prevValues) => {
const errors = {};
if (!values.name) {
errors.name = 'Name is required';
}
if (values.age && values.age < 18) {
errors.age = 'Must be at least 18';
}
return errors;
});
const handleSubmit = (e) => {
e.preventDefault();
if (isValid) {
console.log(form.values);
}
};
// If you want to render the form values:
// const nameValue = useFormWatch(form, 'name');
// const formValuesObj = useFormWatch(form);
return (
<form onSubmit={handleSubmit}>
<input
name="name"
defaultValue={form.values.name}
onChange={(e) => form.setValue('name', e.currentTarget.value)}
/>
{errors.name && <span className="error">{errors.name}</span>}
<input
name="age"
defaultValue={form.values.age}
onChange={(e) => form.setValue('name', e.currentTarget.value)}
/>
{errors.name && <span className="error">{errors.name}</span>}
<button type="submit" disabled={!isValid}>
Submit
</button>
</form>
);
};
For more advanced examples, check out the example directory.
FAQs
A React library for building forms with ease, providing hooks for managing form state and validation in React applications.
We found that @avinlab/react-form demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.