Skip to content

Commit f11a686

Browse files
Kamal Sai DevarapalliKamal Sai Devarapalli
authored andcommitted
fix: Remove warnings from useDeepCompareEffect (fixes #755)
Removes console.warn statements that were causing frustration for valid use cases where dependencies could be either undefined or an object. The hook works correctly regardless of dependency types (primitives, objects, or mixed), so the warnings were unnecessary and frustrating for developers with valid use cases. This directly addresses issue #755 where users reported frustration with warnings appearing in local development environments when using the hook with dependencies that could be undefined or objects.
1 parent 9ef9535 commit f11a686

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed

docs/useDeepCompareEffect.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ const Demo = () => {
2323
};
2424
```
2525

26+
## Valid Use Cases
27+
28+
This hook is particularly useful when:
29+
- Dependencies could be either `undefined` or an object that you'd like to be deep-compared
30+
- You need to compare complex objects by value rather than reference
31+
- Dependencies may include primitive values mixed with objects
32+
33+
The hook works correctly with any dependency array, including primitives, objects, or mixed types.
34+
2635
## Reference
2736

2837
```ts

src/useDeepCompareEffect.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,7 @@ import { DependencyList, EffectCallback } from 'react';
22
import useCustomCompareEffect from './useCustomCompareEffect';
33
import isDeepEqual from './misc/isDeepEqual';
44

5-
const isPrimitive = (val: any) => val !== Object(val);
6-
75
const useDeepCompareEffect = (effect: EffectCallback, deps: DependencyList) => {
8-
if (process.env.NODE_ENV !== 'production') {
9-
if (!(deps instanceof Array) || !deps.length) {
10-
console.warn(
11-
'`useDeepCompareEffect` should not be used with no dependencies. Use React.useEffect instead.'
12-
);
13-
}
14-
15-
if (deps.every(isPrimitive)) {
16-
console.warn(
17-
'`useDeepCompareEffect` should not be used with dependencies that are all primitive values. Use React.useEffect instead.'
18-
);
19-
}
20-
}
21-
226
useCustomCompareEffect(effect, deps, isDeepEqual);
237
};
248

0 commit comments

Comments
 (0)