mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 05:40:31 +00:00
re-structure to monorepo.
This commit is contained in:
25
packages/webapp/src/hooks/utils/useDeepCompareEffect.ts
Normal file
25
packages/webapp/src/hooks/utils/useDeepCompareEffect.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
// @ts-nocheck
|
||||
import { DependencyList, EffectCallback } from 'react';
|
||||
import isDeepEqualReact from 'fast-deep-equal/react';
|
||||
import { useCustomCompareEffect } from './useCustomCompareEffect';
|
||||
|
||||
const isPrimitive = (val: any) => val !== Object(val);
|
||||
|
||||
const useDeepCompareEffect = (effect: EffectCallback, deps: DependencyList) => {
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
if (!(deps instanceof Array) || !deps.length) {
|
||||
console.warn(
|
||||
'`useDeepCompareEffect` should not be used with no dependencies. Use React.useEffect instead.',
|
||||
);
|
||||
}
|
||||
|
||||
if (deps.every(isPrimitive)) {
|
||||
console.warn(
|
||||
'`useDeepCompareEffect` should not be used with dependencies that are all primitive values. Use React.useEffect instead.',
|
||||
);
|
||||
}
|
||||
}
|
||||
useCustomCompareEffect(effect, deps, isDeepEqualReact);
|
||||
};
|
||||
|
||||
export { useDeepCompareEffect };
|
||||
Reference in New Issue
Block a user