import { C as CompareFn } from './react-tools.Bn4eWtTP.js'; import { D as DependencyListTyped } from './react-tools.Ozx07lAu.js'; import { Ref } from 'react'; /** * Parameters accepted by [useCallbackCompare](https://react-tools.ndria.dev/hooks/performance/useCallbackCompare). * * @template T - The type of the callback function to memoize. Inferred automatically from the `cb` argument. * @template E - The tuple type of the dependency list. Inferred automatically from the `deps` argument, providing stricter typing than the standard `DependencyList`. */ type UseCallbackCompareProps = { /** * The callback function to memoize. Returned as-is when the dependencies * are considered unchanged by `compareFn`. A new reference is returned only * when `compareFn` determines that at least one dependency has changed. */ cb: T; /** * A strictly-typed dependency array (same semantics as `useCallback`). Passed * to `compareFn` on each render to determine whether the memoized callback * should be updated. Using {@link DependencyListTyped} instead of the standard * `DependencyList` provides compile-time checking of dependency types. */ deps: DependencyListTyped; /** * An optional custom comparison function used to decide whether the dependencies * have changed between renders. Receives the previous and next dependency arrays * and should return `true` when they are considered equal (i.e. the callback * should be kept) and `false` when they differ (i.e. a new callback reference * should be returned). When omitted, a deep equality check is used by default. */ compareFn?: CompareFn; }; /** * Return value of [useCallbackCompare](https://react-tools.ndria.dev/hooks/performance/useCallbackCompare). * * The memoized version of `cb`, with the same type and signature as the original. * A new reference is only returned when `compareFn` determines that the dependencies * have changed; otherwise the previous reference is preserved across renders. * * @template T - The type of the original callback function. */ type UseCallbackCompareResult = T; /** * Parameters accepted by [useLazyRef](https://react-tools.ndria.dev/hooks/performance/useLazyRef). * * @template T - The type of the value produced by the initializer and stored in the ref. Inferred automatically from the return type of `initializer`. */ type UseLazyRefProps = { /** * A factory function invoked exactly once on the first render to produce the * initial value stored in the ref. Unlike passing a value directly to * `useRef`, this avoids re-creating expensive objects on every render — * the initializer is only called when the ref is first created. */ initializer: () => T; }; /** * Return value of [useLazyRef](https://react-tools.ndria.dev/hooks/performance/useLazyRef). * * A mutable ref object whose `.current` property is initialised lazily on the * first render via `initializer` and persists for the lifetime of the component. * Mutating `.current` does not trigger a re-render. * * @template T - The type of the value stored in the ref. */ type UseLazyRefResult = React.MutableRefObject; /** * Parameters accepted by [useMemoCompare](https://react-tools.ndria.dev/hooks/performance/useMemoCompare). * * @template T - The type of the memoized value produced by `cb`. Inferred automatically from its return type. * @template E - The tuple type of the dependency list. Inferred automatically from the `deps` argument, providing stricter typing than the standard `DependencyList`. */ type UseMemoCompareProps = { /** * A factory function that computes the memoized value. Re-invoked only when * `compareFn` determines that the dependencies have changed between renders. * When the dependencies are considered unchanged, the previous value is * returned without calling `cb` again. */ cb: () => T; /** * A strictly-typed dependency array (same semantics as `useMemo`). Passed to * `compareFn` on each render to determine whether the memoized value should * be recomputed. Using {@link DependencyListTyped} instead of the standard * `DependencyList` provides compile-time checking of dependency types. */ deps: DependencyListTyped; /** * An optional custom comparison function used to decide whether the dependencies * have changed between renders. Receives the previous and next dependency arrays * and should return `true` when they are considered equal (i.e. the memoized * value should be kept) and `false` when they differ (i.e. `cb` should be * re-invoked). When omitted, a deep equality check is used by default. */ compareFn?: CompareFn; }; /** * Return value of [useMemoCompare](https://react-tools.ndria.dev/hooks/performance/useMemoCompare). * * The memoized value returned by `cb`. Recomputed only when `compareFn` * determines that the dependencies have changed; otherwise the previous * value is preserved across renders. * * @template T - The type of the memoized value. */ type UseMemoCompareResult = T; /** * Parameters accepted by [useMemoizedFn](https://react-tools.ndria.dev/hooks/performance/useMemoizedFn). * * @template T - The type of the function to memoize. Must be a callable with any argument and return type. Inferred automatically from the `fn` argument. */ type UseMemoizedFnProps any> = { /** * The function to wrap with a stable reference. The returned function always * delegates to the latest version of `fn` captured during the most recent * render, without the stable wrapper identity ever changing between renders. * Useful as a replacement for `useCallback` when the dependency array would * be large or difficult to maintain. */ fn: T; }; /** * Return value of [useMemoizedFn](https://react-tools.ndria.dev/hooks/performance/useMemoizedFn). * * A stable function with the same signature as `fn` whose identity never changes * between renders. Internally always calls the latest version of `fn`, so it is * safe to use as an event handler or effect dependency without causing unnecessary * re-runs. * * @template T - The type of the original function. */ type UseMemoizedFnResult any> = T; /** * Parameters accepted by [useMergedRef](https://react-tools.ndria.dev/hooks/performance/useMergedRef). * * @template T - The element or value type that all refs point to. */ type UseMergedRefProps = { /** * A variadic list of React refs to merge. Each entry may be a * `RefCallback`, a `MutableRefObject`, or `null`. When the merged ref * is set, all provided refs are updated simultaneously with the same value, * allowing multiple consumers to observe the same DOM element or imperative * handle. */ refs: Ref[]; }; /** * Return value of [useMergedRef](https://react-tools.ndria.dev/hooks/performance/useMergedRef). * * A single stable {@link Ref} that, when attached to a JSX element, forwards * the resolved value to every ref passed as input. Compatible with both * `ref` props on DOM elements and `forwardRef` patterns. * * @template T - The element or value type that the merged ref points to. */ type UseMergedRefResult = Ref; /** * **`useCallbackCompare`**: custom useCallback that returns memoized callback that changes only when comparator function, received as third parameter, returns true. * @see [📖 Documentation](https://react-tools.ndria.dev/hooks/performance/useCallbackCompare) * @template T - The type of the callback function to memoize. Inferred automatically from the `cb` argument. * @template E - The tuple type of the dependency list. Inferred automatically from the `deps` argument, providing stricter typing than the standard `DependencyList`. * @param {UseCallbackCompareProps["cb"]} cb - {@link UseCallbackCompareProps} * @param {UseCallbackCompareProps["deps"]} deps - {@link UseCallbackCompareProps} * @param {UseCallbackCompareProps["compareFn"]} [compareFn] - {@link UseCallbackCompareProps} * @returns {UseCallbackCompareResult} result - {@link UseCallbackCompareResult} */ declare const useCallbackCompare: (cb: UseCallbackCompareProps["cb"], deps: UseCallbackCompareProps["deps"], compareFn?: UseCallbackCompareProps["compareFn"]) => UseCallbackCompareResult; /** * **`useCallbackDeepCompare`**: custom useCallback that returns memoized callback that changes only if deps are different in depth. * @see [📖 Documentation](https://react-tools.ndria.dev/hooks/performance/useCallbackDeepCompare) * @template T - The type of the callback function to memoize. Inferred automatically from the `cb` argument. * @param {UseCallbackCompareProps["cb"]} cb - {@link UseCallbackCompareProps} * @param {UseCallbackCompareProps["deps"]} deps - {@link UseCallbackCompareProps} * @returns {UseCallbackCompareResult} result - {@link UseCallbackCompareResult} */ declare const useCallbackDeepCompare: (cb: UseCallbackCompareProps["cb"], deps: UseCallbackCompareProps["deps"]) => UseCallbackCompareResult; /** * **`useMemoizedFn`**: Hook to store a function that will never change while keeping its dependencies always up to date. Can be used instead of _useCallback_, without esplicity dependencies array. * @see [📖 Documentation](https://react-tools.ndria.dev/hooks/performance/useMemoizedFn) * @template T - The type of the function to memoize. Must be a callable with any argument and return type. Inferred automatically from the `fn` argument. * @param {UseMemoizedFnProps["fn"]} fn - {@link UseMemoizedFnProps} * @returns {UseMemoizedFnResult} result - {@link UseMemoizedFnResult} */ declare const useMemoizedFn: any>(fn: UseMemoizedFnProps["fn"]) => UseMemoizedFnResult; /** * **`useMemoCompare`**: custom useMemo that returns memoized value that changes only when comparator function, received as third parameter, returns true. * @see [📖 Documentation](https://react-tools.ndria.dev/hooks/performance/useMemoCompare) * @template T - The type of the memoized value produced by `cb`. Inferred automatically from its return type. * @template E - The tuple type of the dependency list. Inferred automatically from the `deps` argument, providing stricter typing than the standard `DependencyList`. * @param {UseMemoCompareProps["cb"]} cb - {@link UseMemoCompareProps} * @param {UseMemoCompareProps["deps"]} deps - {@link UseMemoCompareProps} * @param {UseMemoCompareProps["compareFn"]} [compareFn] - {@link UseMemoCompareProps} * @returns {UseMemoCompareResult} result - {@link UseMemoCompareResult} */ declare const useMemoCompare: (cb: UseMemoCompareProps["cb"], deps: UseMemoCompareProps["deps"], compareFn?: UseMemoCompareProps["compareFn"]) => UseMemoCompareResult; /** * **`useMemoDeepCompare`**: custom useMemo that returns memoized value that changes only if deps are different in depth. * @see [📖 Documentation](https://react-tools.ndria.dev/hooks/performance/useMemoDeepCompare) * @template T - The type of the memoized value produced by `cb`. Inferred automatically from its return type. * @param {UseMemoCompareProps["cb"]} cb - {@link UseMemoCompareProps} * @param {UseMemoCompareProps["deps"]} deps - {@link UseMemoCompareProps} * @returns {UseMemoCompareResult} result - {@link UseMemoCompareResult} */ declare const useMemoDeepCompare: (cb: UseMemoCompareProps["cb"], deps: UseMemoCompareProps["deps"]) => UseMemoCompareResult; /** * **`useMergedRef`**: Hook to merge multiple refs into one. * @see [📖 Documentation](https://react-tools.ndria.dev/hooks/performance/useMergedRef) * @param {UseMergedRefProps["refs"]} refs - {@link UseMergedRefProps} * @returns {UseMergedRefResult} result - {@link UseMergedRefResult} */ declare const useMergedRef: (...refs: UseMergedRefProps["refs"]) => UseMergedRefResult; /** * **`useLazyRef`**: Hook that works 'partially' like the _useState_ hook with lazy initialization: ensures that the __initializer__ function is executed only once. * @see [📖 Documentation](https://react-tools.ndria.dev/hooks/performance/useLazyRef) * @template T - The type of the value produced by the initializer and stored in the ref. Inferred automatically from the return type of `initializer`. * @param {UseLazyRefProps["initializer"]} initializer - {@link UseLazyRefProps} * @returns {UseLazyRefResult} result - {@link UseLazyRefResult} */ declare const useLazyRef: (initializer: UseLazyRefProps["initializer"]) => UseLazyRefResult; /** * __`useId`__: _useId_ hook polyfilled for React versions below 18: __not use for key prop__. * @see [📖 Documentation](https://react-tools.ndria.dev/hooks/performance/useId) * @returns {string} result */ declare function useIdPolyfilled(): string; declare const useId: typeof useIdPolyfilled; export { useCallbackDeepCompare as a, useId as b, useLazyRef as c, useMemoCompare as d, useMemoDeepCompare as e, useMemoizedFn as f, useMergedRef as g, useCallbackCompare as u }; export type { UseCallbackCompareProps as U, UseCallbackCompareResult as h, UseLazyRefProps as i, UseLazyRefResult as j, UseMemoCompareProps as k, UseMemoCompareResult as l, UseMemoizedFnProps as m, UseMemoizedFnResult as n, UseMergedRefProps as o, UseMergedRefResult as p };