diff --git a/src/lib/index.ts b/src/lib/index.ts index 11626852..820f43e7 100644 --- a/src/lib/index.ts +++ b/src/lib/index.ts @@ -5,7 +5,6 @@ export * from './schemas' export { useLoadApp } from './useLoadApp' export type { ModelSchemas, Schema } from './useLoadApp' export * from './errors' -export { memoize } from './memoize' export * from './user' export * from './sections' export * from './useDebounce' diff --git a/src/lib/memoize.ts b/src/lib/memoize.ts deleted file mode 100644 index b6f1f352..00000000 --- a/src/lib/memoize.ts +++ /dev/null @@ -1,33 +0,0 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ - -const doArgsMatch = (prev: any[], next: any[]) => { - if (!prev && !next) { - return true - } - - if (prev?.length !== next?.length) { - return false - } - - return prev.every((value, index) => value === next[index]) -} - -// eslint-disable-next-line @typescript-eslint/ban-types -export function memoize(fn: Function) { - let called = false - let args: any - let value: any - - return (...nextArgs: any[]) => { - const argsMatch = called && doArgsMatch(args, nextArgs) - called = true - - if (argsMatch) { - return value - } - - args = nextArgs - value = fn(...nextArgs) - return value - } -} diff --git a/src/pages/dataElements/form/useIsFieldValueUnique.ts b/src/pages/dataElements/form/useIsFieldValueUnique.ts index f7ead0f5..8f4e65ac 100644 --- a/src/pages/dataElements/form/useIsFieldValueUnique.ts +++ b/src/pages/dataElements/form/useIsFieldValueUnique.ts @@ -1,8 +1,8 @@ import { useDataEngine } from '@dhis2/app-runtime' import i18n from '@dhis2/d2-i18n' +import memoize from 'lodash/memoize' import { useMemo } from 'react' import { useDebouncedCallback } from 'use-debounce' -import { memoize } from '../../../lib' import { Pager } from '../../../types/generated' const HAS_FIELD_VALUE_QUERY = {