I created a user login using my Reusable Input Component. I having an issue with how I can implement my validation using react-hook-form 6.
login.js
const { register, handleSubmit, errors } = useForm({
mode: 'onSubmit',
reValidateMode: 'onClick',
defaultValues: {
username: '',
password: '',
}
});
<form
noValidate
onSubmit={handleSubmit(onSubmit)}
>
<InputField
type='text'
placeholder='Email or Username'
name='username'
value={userInfo.username}
onChange={handleChange}
inputRef={register({
required: 'You must provide a title.',
})}
/>
{errors.username && (
<span className='text-red-900'>{errors.username.message}</span>
)}
<Button type='submit' caption='Sign In' />
</form>
components/InputField.js
const InputField = ({ value, label, name, placeholder, type, onChange }) => (
<div className='form-group w-full'>
{label && <label htmlFor='input-field'>{label}</label>}
<input
type={type}
value={value}
name={name}
className='bg-customBlack-light w-full text-xs p-4 mb-6 rounded-md outline-none transition duration-150 ease-in-out'
placeholder={placeholder}
onChange={onChange}
/>
</div>
);