Skip to content

Instantly share code, notes, and snippets.

@kwoncharles
Created March 1, 2020 09:27
Show Gist options
  • Select an option

  • Save kwoncharles/dfb5d2202dcc92353a830e6ed0441fcc to your computer and use it in GitHub Desktop.

Select an option

Save kwoncharles/dfb5d2202dcc92353a830e6ed0441fcc to your computer and use it in GitHub Desktop.
useInput hook example
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