Created
March 1, 2020 09:27
-
-
Save kwoncharles/dfb5d2202dcc92353a830e6ed0441fcc to your computer and use it in GitHub Desktop.
useInput hook example
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
| function SomeComponent() { | |
| const [value, onChangeInputValue, isValid] = useInput({ | |
| type: 'number', | |
| maxValue: 10000, | |
| autoFix: false, | |
| }); | |
| const onSubmit = () => { | |
| if (isValid) { | |
| submitValue(value); | |
| } else { | |
| setError(); | |
| } | |
| } | |
| // ... | |
| return ( | |
| <form onSubmit={onSubmit}> | |
| <input | |
| value={value} | |
| onChange={onChangeInputValue} | |
| /> | |
| {/* ... */} | |
| </form> | |
| ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment