import { useMemo } from 'react' import type { FieldMeta } from '../../types' import type { Value } from './item-form' export function useInvalidFields ( fields: Record, value: Value ): ReadonlySet { return useMemo(() => { const invalidFields = new Set() Object.keys(value).forEach(fieldPath => { const val = value[fieldPath] if (val.kind === 'value') { const validateFn = fields[fieldPath].controller.validate if (validateFn) { const result = validateFn(val.value) if (result === false) { invalidFields.add(fieldPath) } } } }) return invalidFields }, [fields, value]) }