import { __LEGIT_ANY_FUNCTION__ } from "@ls-stack/utils/saferTyping"; //#region src/useLatestValue.d.ts type UseLatestValue = { insideEffect: T; }; /** * Hook that provides access to the latest value within effects and callbacks. * * Returns an object with `insideEffect` property that always contains the most * recent value * * @param value - The value to keep track of * @returns Object with `insideEffect` property containing the latest value * * @example * ```tsx * function MyComponent({ count }: { count: number }) { * const latestCount = useLatestValue(count); * * useEffect(() => { * const timer = setInterval(() => { * // Always gets the latest count value, even in stale closure * console.log('Current count:', latestCount.insideEffect); * }, 1000); * * return () => clearInterval(timer); * }, [latestCount]); * } * ``` */ declare function useLatestValue(value: T): UseLatestValue; /** * Hook that provides a stable callback reference that always calls the latest version of the function. * * @param fn - The function to wrap * @returns A stable callback that always calls the latest version of the function * * @example * ```tsx * function MyComponent({ onDataChange, data }: { onDataChange: (data: any) => void; data: any }) { * const latestCallback = useLatestCb(onDataChange); * * useEffect(() => { * const interval = setInterval(() => { * // Always calls the latest onDataChange function, even with empty deps * latestCallback(data); * }, 1000); * * return () => clearInterval(interval); * }, [latestCallback]); // it is a stable ref that never changes * } * ``` */ declare function useLatestCb(fn: T): T; //#endregion export { UseLatestValue, useLatestCb, useLatestValue };