Created
July 28, 2019 11:45
-
-
Save DJanoskova/5883691236753532adbbc3b7568ba562 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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