@ej-hooks/use-input
React Hook to update input with validator.
Installation
yarn
yarn add @ej-hooks/use-input
npm
npm i @ej-hooks/use-input
Usage
import React from 'react';
import useInput from '@ej-hooks/use-input';
function App() {
const maxLen = (value) => value.length <= 10;
//const noAt = (value) => !value.includes('@');
const name = useInput('Mr.', maxLen);
return <input placeholder="Name" {...name} />;
}
Arguments
Argument | Type | Description | Required |
---|---|---|---|
initialValue | string | Initial input value | yes |
validator | function | Function to validate the input value | no |