@react-hookz/web
Version:
React hooks done right, for browser and SSR.
21 lines (20 loc) • 1.54 kB
TypeScript
import { DependencyList } from 'react';
import { IEffectCallback, IEffectHook } from '..';
export declare type IConditionsList = ReadonlyArray<any>;
export declare type IConditionsPredicate<Cond extends IConditionsList = IConditionsList> = (conditions: Cond) => boolean;
/**
* Like `useEffect` but callback invoked only if conditions match predicate.
*
* @param callback Function that will be passed to underlying effect hook.
* @param deps Dependencies list like for `useEffect`. If not undefined - effect will be
* triggered when deps change AND conditions satisfy predicate.
* @param conditions Conditions array.
* @param predicate Predicate that defines whether conditions satisfying certain
* provision. By default, it is all-truthy provision, meaning that all
* conditions should be truthy.
* @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 are passed to `effectHook`.
*/
export declare function useConditionalEffect<Cond extends IConditionsList, Callback extends IEffectCallback = IEffectCallback, Deps extends DependencyList | undefined = DependencyList | undefined, HookRestArgs extends any[] = any[], R extends HookRestArgs = HookRestArgs>(callback: Callback, deps: Deps, conditions: Cond, predicate?: IConditionsPredicate<Cond>, effectHook?: IEffectHook<Callback, Deps, HookRestArgs>, ...effectHookRestArgs: R): void;