mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-14 23:30:53 -05:00
7f8d2e37d5
[web] Payment page migration checkout panel GitOrigin-RevId: 04edf9961e0032d6fe3631c255e49dc1d4c3e0ca
21 lines
465 B
TypeScript
21 lines
465 B
TypeScript
import { useState } from 'react'
|
|
|
|
type Target = HTMLInputElement | HTMLSelectElement
|
|
|
|
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
|