
Security News
TypeScript is Porting Its Compiler to Go for 10x Faster Builds
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
@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.
Security News
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
Research
Security News
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.