@supunlakmal/hooks
Version:
A collection of reusable React hooks
18 lines (17 loc) • 995 B
TypeScript
import { EffectCallback, DependencyList } from 'react';
export declare const isDeepEqual: (objA: any, objB: any) => boolean;
/**
* A custom effect hook that deeply compares its dependencies instead of using
* shallow reference comparison (like the standard `useEffect`).
*
* Useful when effect dependencies are objects or arrays that might be recreated
* on each render but are structurally identical.
*
* **Warning:** Deep comparison can be computationally expensive. Use judiciously
* and prefer memoizing complex dependencies with `useMemo` or `useCallback` where possible.
* Consider using a more robust deep comparison library (e.g., `lodash.isequal`).
*
* @param effect Imperative function that can return a cleanup function.
* @param dependencies Array of dependencies. The effect runs only if these dependencies are deeply unequal compared to the previous render.
*/
export declare const useDeepCompareEffect: (effect: EffectCallback, dependencies: DependencyList) => void;