Skip to content

Instantly share code, notes, and snippets.

@DJanoskova
Created July 28, 2019 11:45
Show Gist options
  • Select an option

  • Save DJanoskova/5883691236753532adbbc3b7568ba562 to your computer and use it in GitHub Desktop.

Select an option

Save DJanoskova/5883691236753532adbbc3b7568ba562 to your computer and use it in GitHub Desktop.
const CustomForm = () => {
const defaultValues = {
username: '',
email: '',
age: ''
};
const customErrorAttribute = {
className: 'has-error',
'another-attr': 'look-at-me'
};
const { values, useInput, isValid } = useForm(defaultValues, customErrorAttribute);
const handleSubmit = e => {
e.preventDefault();
console.log(values)
};
return (
<form onSubmit={handleSubmit}>
<div className="form-body">
<label>Username *</label>
<input
type="text"
{...useInput('username', {
isRequired: true
})}
/>
<label>E-mail</label>
<input
type="text"
{...useInput('email', 'isEmail')}
/>
<label>Age</label>
<input
type="text"
{...useInput('age', {
isInt: {
min: 1
}
})}
/>
</div>
<button type="submit" disabled={!isValid}>
Submit
</button>
</form>
)
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment