import { useMemo } from 'react' ; import { BITS , useFormContext } from './Contexts' ; import memoize from 'memoize-one' ; import { filterAndMapErrors } from './Errors' ; import { Errors , Touched } from './types' ; returns { Touched } function useTouched ( ) ; param path returns { Touched } function useTouched ( path ) ; param paths returns { Touched } function useTouched ( paths ) ; function useTouched ( paths ? ) { const { touched } = useFormContext ( BITS . touched ) ; const memoFilterAndMapErrors = useMemo ( ( ) => memoize ( filterAndMapErrors , ( [ a ] , [ b ] ) => a . errors === b . errors && a . names === b . names && a . mapErrors === b . mapErrors ) , [ ] ) ; return paths ? memoFilterAndMapErrors ( { errors : touched , names : paths } ) : touched ; } export default useTouched ;