import { useCallback, useEffect, useState } from 'react';
import { useSyncedRef } from '../useSyncedRef/index.js';
export function useValidator(validator, deps, initialValidity = { isValid: undefined }) {
    const [validity, setValidity] = useState(initialValidity);
    const validatorRef = useSyncedRef(() => {
        if (validator.length > 0) {
            validator(setValidity);
        }
        else {
            setValidity(validator());
        }
    });
    useEffect(() => {
        validatorRef.current();
    }, deps);
    return [
        validity,
        useCallback(() => {
            validatorRef.current();
        }, []),
    ];
}
