packages/material-ui-lab/src/internal/pickers/hooks/useValidation.ts/makeValidationHook
export function makeValidationHook<
  TError,
  TDateValue,
  TProps extends ValidationProps<TError, TDateValue>
>(
  validateFn: (utils: MuiPickersAdapter, value: TDateValue, props: TProps) => TError,
  { defaultValidationError, isSameError = defaultIsSameError }: ValidationHookOptions<TError> = {},
) {
  return (value: TDateValue, props: TProps) => {
    const utils = useUtils();
    const previousValidationErrorRef = React.useRef<TError>(
      defaultValidationError || null,
    ) as React.MutableRefObject<TError>;

    const validationError = validateFn(utils, value, props);

    React.useEffect(() => {
      if (props.onError && !isSameError(validationError, previousValidationErrorRef.current)) {
        props.onError(validationError, value);
      }

      previousValidationErrorRef.current = validationError;
    }, [previousValidationErrorRef, props, validationError, value]);

    return validationError;
  };
}