Skip to content

Commit f2d6a2d

Browse files
Kamal Sai DevarapalliKamal Sai Devarapalli
authored andcommitted
fix: remove warnings from useDeepCompareEffect
Removes the console warnings that were showing up in dev. The hook works fine with primitives, objects, or undefined - the warnings were just annoying for valid use cases. Fixes #755
1 parent 9ef9535 commit f2d6a2d

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+
## When to Use
27+
28+
This hook is handy when:
29+
- Your dependencies might be `undefined` or an object (common with optional props/config)
30+
- You need to compare objects by their values, not just references
31+
- You're mixing primitives and objects in your dependency array
32+
33+
Works fine with any dependency types - primitives, objects, or a mix of both.
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)