UNPKG

1.32 kBTypeScriptView Raw
1import { DependencyList, EffectCallback } from 'react';
2export declare type EffectHook = (effect: EffectCallback, deps?: DependencyList) => void;
3export declare type IsEqual<TDeps extends DependencyList> = (nextDeps: TDeps, prevDeps: TDeps) => boolean;
4export declare type CustomEffectOptions<TDeps extends DependencyList> = {
5 isEqual: IsEqual<TDeps>;
6 effectHook?: EffectHook;
7};
8/**
9 * a useEffect() hook with customized depedency comparision
10 *
11 * @param effect The effect callback
12 * @param dependencies A list of dependencies
13 * @param isEqual A function comparing the next and previous dependencyLists
14 */
15declare function useCustomEffect<TDeps extends DependencyList = DependencyList>(effect: EffectCallback, dependencies: TDeps, isEqual: IsEqual<TDeps>): void;
16/**
17 * a useEffect() hook with customized depedency comparision
18 *
19 * @param effect The effect callback
20 * @param dependencies A list of dependencies
21 * @param options
22 * @param options.isEqual A function comparing the next and previous dependencyLists
23 * @param options.effectHook the underlying effect hook used, defaults to useEffect
24 */
25declare function useCustomEffect<TDeps extends DependencyList = DependencyList>(effect: EffectCallback, dependencies: TDeps, options: CustomEffectOptions<TDeps>): void;
26export default useCustomEffect;