diff --git a/src/hooks/index.ts b/src/hooks/index.ts index 39ed321..128c6e8 100644 --- a/src/hooks/index.ts +++ b/src/hooks/index.ts @@ -1,5 +1,6 @@ export * from './useBoolean'; export { default as useBoolean } from './useBoolean'; +export { default as useLatestFunc } from './useLatestFunc'; export * from './useModalEnhanced'; export { default as useModalEnhanced } from './useModalEnhanced'; diff --git a/src/util/use-latest-func.ts b/src/hooks/useLatestFunc.ts similarity index 57% rename from src/util/use-latest-func.ts rename to src/hooks/useLatestFunc.ts index 192c3a2..79321fe 100644 --- a/src/util/use-latest-func.ts +++ b/src/hooks/useLatestFunc.ts @@ -2,9 +2,10 @@ import { useCallback, useEffect, useRef } from 'react'; type Maybe = T | undefined | null; -// https://reactjs.org/docs/hooks-faq.html#what-can-i-do-if-my-effect-dependencies-change-too-often -// eslint-disable-next-line @typescript-eslint/no-explicit-any -export function useLatestFunc any>>(fn: T): T { +/** + * @see https://reactjs.org/docs/hooks-faq.html#what-can-i-do-if-my-effect-dependencies-change-too-often + */ +function useLatestFunc any>>(fn: T): T { const ref = useRef(fn); useEffect(() => { @@ -18,3 +19,5 @@ export function useLatestFunc any>>(fn: T): // @ts-expect-error return fn ? callbackFn : fn; } + +export default useLatestFunc; diff --git a/src/hooks/useModalEnhanced.ts b/src/hooks/useModalEnhanced.ts index 930e796..277af91 100644 --- a/src/hooks/useModalEnhanced.ts +++ b/src/hooks/useModalEnhanced.ts @@ -1,8 +1,9 @@ import React from 'react'; import { useEasyAntdModal } from '../context'; import type { AnyFunction, AnyObj } from '../types'; -import { has, isDOMTypeElement, isElement, omit, useLatestFunc } from '../util'; +import { has, isDOMTypeElement, isElement, omit } from '../util'; import useBoolean from './useBoolean'; +import useLatestFunc from './useLatestFunc'; export type PropsWithModalEnhanced< P extends AnyObj = AnyObj, diff --git a/src/util/index.ts b/src/util/index.ts index 1a29187..67ab45b 100644 --- a/src/util/index.ts +++ b/src/util/index.ts @@ -1,4 +1,3 @@ export * from './has'; export * from './omit'; export * from './react-is'; -export * from './use-latest-func';