import Collection from "@arcgis/core/core/Collection"; import type { Evented } from "@arcgis/core/core/Evented"; import useResizeObserver from "@react-hook/resize-observer"; import type { EventCallback as EsriEventCallback } from "@vertigis/arcgis-extensions/support/esri"; import { type Observable, type ObservablePropertyPath, type TargetTypeFromPath, type ValueTypeFromPath } from "@vertigis/arcgis-extensions/support/observableUtils"; import type { ComponentType } from "react"; import type { Event, EventCallback } from "../messaging"; export { default as mergeRefs } from "merge-refs"; /** * A hook that allows you to see if the current component is mounted. Uses * 'useLayoutEffect' as it is common to be referenced by other component * effects. */ export declare function useIsMounted(): () => boolean; /** * Watches an object for changes in one or more properties and triggers a * callback. * * @param obj The object to watch. * @param path The property path(s) to watch on the object. * @param callback The callback to invoke when the property changes. * @param deps The component prop(s) that this hook depends on. See the React * documentation for `useEffect()` for more info. If you specify a value for * this parameter, then at minimum the array should include the other * arguments to this function. */ export declare function useWatch, TValue extends ValueTypeFromPath>(obj: TObsv, path: TPath, callback: (newValue: TValue, oldValue: TValue) => void, deps?: unknown[]): void; /** * Same as `useWatch()`, except that it also invokes the callback with the * initial value of the property. * * @param obj The object to watch. * @param path The property path(s) to watch on the object. * @param callback The callback to invoke initially and when the property * changes. * @param deps The component prop(s) that this hook depends on. See the React * documentation for `useEffect()` for more info. If you specify a value for * this parameter, then at minimum the array should include the other * arguments to this function. */ export declare function useWatchInit, TValue extends ValueTypeFromPath>(obj: TObsv, path: TPath, callback: (newValue: TValue, oldValue: TValue) => void, deps?: unknown[]): void; /** * Watches an object for changes in one or more properties and triggers a * re-render. * * @param obj The object to watch. * @param path The property path(s) to watch on the object. */ export declare function useWatchAndRerender>(obj: TObsv, path: TPath | TPath[]): void; /** * Watches a collection for change events and triggers a re-render. * * @param collection The collection to watch. */ export declare function useWatchCollectionAndRerender(collection: Collection): void; /** * Watches one or more properties on each item in a collection for changes and * triggers a callback when any one of the properties change. * * @param collectionLike The collection or array to watch. * @param path The property path(s) to watch on each item in the collection. * @param callback The callback to invoke when the property changes. * @param deps The component prop(s) that this hook depends on. See the React * documentation for `useEffect()` for more info. If you specify a value for * this parameter, then at minimum the array should include the other * arguments to this function. */ export declare function useWatchEach, TValue extends ValueTypeFromPath, TTarget extends TargetTypeFromPath>(collectionLike: Collection | TObsv[], path: TPath, callback: (newValue: TValue, oldValue: TValue, target: TTarget) => void, deps?: unknown[]): void; /** * Watches one or more properties on each item in a collection for changes and * triggers a re-render when any one of the properties change. * * @param collectionLike The collection or array to watch. * @param path The property path(s) to watch on each item in the collection. */ export declare function useWatchEachAndRerender>(collectionLike: Collection | TObsv[], path: TPath | TPath[]): void; /** * Subscribes to an event and triggers a callback. * * @param obj The object to watch. * @param event The name of the event. * @param callback The callback to invoke when the event is emitted. * @param deps The component prop(s) that this hook depends on. See the React * documentation for `useEffect()` for more info. If you specify a value for * this parameter, then at minimum the array should include `obj`. */ export declare function useSubscribe(obj: Evented, event: string, callback: EsriEventCallback, deps?: unknown[]): void; /** * Subscribes to an event and triggers a callback. * * @param event The event to subscribe to. * @param callback The callback to invoke when the event fires. * @param deps The component prop(s) that this hook depends on. See the React * documentation for `useEffect()` for more info. If you specify a value for * this parameter, then at minimum the array should include `event`. */ export declare function useSubscribe(event: Event, callback: EventCallback, deps?: unknown[]): void; /** * Subscribes to an event and triggers a re-render. * * @param event The event to subscribe to. */ export declare function useSubscribeAndRerender(event: Event): void; /** * Subscribes to an evented object and triggers a re-render. * * @param event An evented object to subscribe to. * @param name The name of the event to subscribe to. */ export declare function useSubscribeAndRerender(event: Evented, name: string): void; /** * Returns a forceUpdate() function, which will force the React component to * re-render. Use sparingly, as per the docs for forceUpdate() in React. */ export declare function useForceUpdate(): () => void; /** * Returns a forceUpdate() function, which will force the React component to * re-render. Use sparingly, as per the docs for forceUpdate() in React. * * Despite the name, this function is actually throttled, not debounced. It uses * animation frames to throttle. */ export declare function useDebouncedForceUpdate(): () => void; /** * Returns a debounced and memoized version of the callback that only changes if * one of the `deps` has changed. * * @param callback The function to debounce and memoize. * @param timeout The debounce delay. * @param deps The dependencies of the callback. */ export declare function useDebounce(callback: (...args: [...T]) => void, timeout: number, deps: unknown[]): (...args: [...T]) => void; /** * Returns a throttled and memoized version of the callback that only changes if * one of the `deps` has changed. * * @param callback The function to throttle and memoize. * @param msBetweenRequests The minimum time in milliseconds between requests. * @param deps The dependencies of the callback. */ export declare function useThrottle(callback: (...args: [...T]) => void, msBetweenRequests: number, deps: unknown[]): (...args: [...T]) => void; /** * Returns a throttled and memoized version of the callback that only changes if * one of the `deps` has changed. * * @param callback The function to throttle and memoize. * @param deps The dependencies of the callback. */ export declare function useThrottleAnimation(callback: (...args: [...T]) => void, deps: unknown[]): (...args: [...T]) => void; /** * Executes a function once when the component is first mounted. The function * will never run again unless the component is unmounted and subsequently * mounted again. * * @param f The function to execute. If the function is async, it's the caller's * responsibility to verify that the component is still mounted after awaiting * any promises (e.g. using `useIsMounted`). */ export declare function useMount(f: () => void | Promise): void; /** * Executes a function once when the component is dismounted. * * @param f The function to execute. */ export declare function useDismount(f: () => void): void; /** * Runs an effect asynchronously. * * @param effect The async effect to run. The callback will be passed an * AbortSignal instance that can be checked after performing some asynchronous * task to determine how (or whether) the rest of the effect should proceed. * If the component is unmounted, the signal will be aborted with the reason * "unmounted". In this case the effect should not invoke things like React * state setters. The signal can also be aborted with the reason "stale", * indicating that there was a newer invocation of the effect. This happens * when either the effect has no dependencies or one of them changed, and the * component was rerendered. In either case, you can use * `signal.throwIfAborted()` to bail out without causing any errors. * @param deps The component prop(s) that this hook depends on. See the React * documentation for `useEffect()` for more info. If you specify a value for * this parameter, then at minimum the array should include the other * arguments to this function. */ export declare function useAsyncEffect(effect: (signal: AbortSignal) => Promise, deps?: unknown[]): void; /** * Runs an effect asynchronously. * * @param effect The async effect to run. The callback will be passed an * AbortSignal instance that can be checked after performing some asynchronous * task to determine how (or whether) the rest of the effect should proceed. * If the component is unmounted, the signal will be aborted with the reason * "unmounted". In this case the effect should not invoke things like React * state setters. The signal can also be aborted with the reason "stale", * indicating that there was a newer invocation of the effect. This happens * when either the effect has no dependencies or one of them changed, and the * component was rerendered. In either case, you can use * `signal.throwIfAborted()` to bail out without causing any errors. * @param cleanup The cleanup code to run. Its purpose and behavior is the same * as the cleanup function for the regular `useEffect` except that it can't be * returned from the main effect. * @param deps The component prop(s) that this hook depends on. See the React * documentation for `useEffect()` for more info. If you specify a value for * this parameter, then at minimum the array should include the other * arguments to this function. * @param otherArgs */ export declare function useAsyncEffect(effect: (signal: AbortSignal) => Promise, cleanup: () => void | Promise, deps?: unknown[]): void; /** * Gets the dimensions of an element. * * @param target A ref to the target element. */ export declare function useContentRect(target: React.RefObject | T): DOMRectReadOnly; /** * Re-renders the component whenever the dimensions of the given element change. * * @param target The target element to watch. */ export declare function useRerenderOnResize(target: React.RefObject | T): void; /** * Produces a unique ID that can be used for the HTML `id` attribute. Will use * the provided value if defined (typically obtained from the calling * component's `id` prop), otherwise one will be generated. The ID will remain * the same between renders (even if `idProp` changes). * * @param idProp The value of the component's `id` prop if there is one. */ export declare function useId(idProp?: string): string; /** * Invokes a callback whenever the dimensions of the given element change. */ export declare const useOnResize: typeof useResizeObserver; /** * Converts a component to a class component. * * @deprecated This function is deprecated and will be removed in a future * version (5.42.0). If you need to convert a function component to a class * component, please do so manually. * @param component The component to convert. */ export declare function toClassComponent(component: ComponentType): ComponentType; /** * Returns the previous value of updated props or state. * * @param value The original value of the property. */ export declare function usePrevious(value: T): T; /** * Hook for iOS-specific zoom detection that invokes a callback when zoom is * detected or undetected. * * @param onZoomChange Callback that is invoked when zoom state changes. The * boolean parameter indicates whether zooming is active (true) or not * (false). */ export declare function useIOSOnlyZoomDetection(onZoomChange: (isZoomed: boolean) => void): void;