@react-hookz/web
Version:
React hooks done right, for browser and SSR.
18 lines (17 loc) • 1.49 kB
TypeScript
import { DependencyList } from 'react';
export declare type IDependenciesComparator<Deps extends DependencyList = DependencyList> = (a: Deps, b: Deps) => boolean;
export declare type IEffectCallback = (...args: any[]) => any;
export declare type IEffectHook<Callback extends IEffectCallback = IEffectCallback, Deps extends DependencyList = DependencyList, RestArgs extends any[] = any[]> = ((...args: [Callback, Deps, ...RestArgs]) => void) | ((...args: [Callback, Deps]) => void);
/**
* Like `useEffect` but uses provided comparator function to validate dependency changes.
*
* @param callback Function that will be passed to underlying effect hook.
* @param deps Dependencies list, like for `useEffect` hook.
* @param comparator Function that compares two dependencies arrays, and returns true in case
* they're equal.
* @param effectHook Effect hook that will be used to run callback. Must comply `useEffect`
* signature, meaning that callback should be placed as first argument and dependencies list
* as second.
* @param effectHookRestArgs Extra arguments that passed to effectHook.
*/
export declare function useCustomCompareEffect<Callback extends IEffectCallback = IEffectCallback, Deps extends DependencyList = DependencyList, HookRestArgs extends any[] = any[], R extends HookRestArgs = HookRestArgs>(callback: Callback, deps: Deps, comparator?: IDependenciesComparator<Deps>, effectHook?: IEffectHook<Callback, Deps, HookRestArgs>, ...effectHookRestArgs: R): void;