UNPKG

@react-hookz/web

Version:

React hooks done right, for browser and SSR.

32 lines (31 loc) 1.5 kB
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { if (ar || !(i in from)) { if (!ar) ar = Array.prototype.slice.call(from, 0, i); ar[i] = from[i]; } } return to.concat(ar || Array.prototype.slice.call(from)); }; import { useEffect } from 'react'; import { isEqual } from '@react-hookz/deep-equal'; import { useCustomCompareEffect, } from "../useCustomCompareEffect/useCustomCompareEffect.js"; /** * Like `useEffect` but uses `@react-hookz/deep-equal` comparator function to validate deep * dependency changes. * * @param callback Function that will be passed to underlying effect hook. * @param deps Dependencies list, like for `useEffect` hook. * @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 function useDeepCompareEffect(callback, deps, effectHook) { if (effectHook === void 0) { effectHook = useEffect; } var effectHookRestArgs = []; for (var _i = 3; _i < arguments.length; _i++) { effectHookRestArgs[_i - 3] = arguments[_i]; } return useCustomCompareEffect.apply(void 0, __spreadArray([callback, deps, isEqual, effectHook], effectHookRestArgs, false)); }