mirror of
https://github.com/streamich/react-use.git
synced 2026-01-18 14:06:52 +00:00
Also reduce max line width to 100. And remove `lint:types` step for commit sequence, it bothers when committing incomplete (wip) changes.
26 lines
840 B
TypeScript
26 lines
840 B
TypeScript
import { DependencyList, EffectCallback } from 'react';
|
|
import useCustomCompareEffect from './useCustomCompareEffect';
|
|
import isDeepEqual from './misc/isDeepEqual';
|
|
|
|
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, isDeepEqual);
|
|
};
|
|
|
|
export default useDeepCompareEffect;
|