mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-13 12:29:32 -05:00
9dba1ccd8f
Add new Name fields for Checkout Redesign GitOrigin-RevId: 448084e026a86510efe3c76c6663c0a770c24f8e
21 lines
487 B
TypeScript
21 lines
487 B
TypeScript
import { useState } from 'react'
|
|
|
|
type Target = HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement
|
|
|
|
function useValidateField<T extends { target: Target }>() {
|
|
const [isValid, setIsValid] = useState(true)
|
|
|
|
const validate = (e: T) => {
|
|
let isValid = e.target.checkValidity()
|
|
|
|
if (e.target.required) {
|
|
isValid = isValid && Boolean(e.target.value.trim().length)
|
|
}
|
|
|
|
setIsValid(isValid)
|
|
}
|
|
|
|
return { validate, isValid }
|
|
}
|
|
|
|
export default useValidateField
|