0.2.4 • Published 4 years ago

react-100-form v0.2.4

Weekly downloads
846
License
MIT
Repository
github
Last release
4 years ago

šŸŽÆ React 100 Form

YES! As the name says, only šŸ’Æ lines of code for a powerful CUSTOM HOOK.

YES! It has most features you might need when dealing with form.

āœ… Zero dependencies (excelent bundle size)

āœ… Only peer dependency: React

āœ… šŸ’„ 1.6k gzipped šŸ’„

Installation

npm install react-100-form

or

yarn add react-100-form

Simple Usage

const initialValues = {name: '', accepted: false};
const validate = (values) => {
	const errorMap = {};
	errorMap.name = values.name === '' && 'Required';
	errorMap.accepted = !values.accepted && 'Should be checked';
	return errorMap;
}
const doSubmit = (values) => { /* your submit logic */ };
const {
	errorMap,
	handleSubmit,
	isValid,
	values
} = useForm(initialValues, validate);
...	...
<form onSubmit={handleSubmit(doSubmit)}>
...	...
<input
	name="name"
	onBlur={handleBlur}
	onChange={handleChange}
	type="text"
	value={values.name}
/>
{errorMap.name && <span>{errorMap.name}</span>}
...	...
<input
	name="accepted"
	onBlur={handleBlur}
	onChange={handleChange}
	type="checkbox"
	value={values.accepted}
/>
{errorMap.accepted && <span>{errorMap.accepted}</span>}
...	...
<button type="submit" disabled={!isValid}>Submit</button>

All features

const {
	commit, // Set current values as inital state
	errorMap,
	handleBlur,
	handleChange,
	handleSubmit,
	isDirty,
	isSubmitting,
	isValid,
	rollBack, // Restore to initial state or to last committed state
	touchedMap,
	values,
} = useForm(
	initialValues,
	validate
);

Author

Mario Medrano Maldonado (Gendecoder) mario.medrano.maldonado@gmail.com

0.2.4

4 years ago

0.2.1

4 years ago

0.2.3

4 years ago

0.2.2

4 years ago

0.1.7

4 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.0

4 years ago

0.1.2

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago