Skip to content

fix(useDeepCompareEffect): remove warning for primitive dependencies#2713

Open
mmustafasenoglu wants to merge 2 commits into
streamich:masterfrom
mmustafasenoglu:fix/remove-deep-compare-primitive-warning
Open

fix(useDeepCompareEffect): remove warning for primitive dependencies#2713
mmustafasenoglu wants to merge 2 commits into
streamich:masterfrom
mmustafasenoglu:fix/remove-deep-compare-primitive-warning

Conversation

@mmustafasenoglu

Copy link
Copy Markdown

Summary

Remove the warning that fires when all dependencies are primitive values. This warning was incorrect because dependencies can change from primitive to non-primitive at runtime (e.g., undefined to an object), making useDeepCompareEffect the correct choice.

The 'no dependencies' warning is preserved as it indicates a likely mistake.

Fixes #755

Changes

Removed the deps.every(isPrimitive) warning check from useDeepCompareEffect.

- if (deps.every(isPrimitive)) {
-   console.warn(
-     '`useDeepCompareEffect` should not be used with dependencies that are all primitive values. Use React.useEffect instead.'
-   );
- }

Context

As noted by @streamich (owner): "I think the warnings for primitives in useDeepCompareEffect (and shallow compare) should be removed." The warning for no dependencies should stay.

The Dispatch type was returning void, which caused TypeScript errors
when using createReducer with redux-thunk or other middleware that
expect the dispatch to return the action.

Fixes streamich#856
Remove the warning that fires when all dependencies are primitive values.
This warning was incorrect because dependencies can change from primitive
to non-primitive at runtime, making useDeepCompareEffect the correct choice.

The 'no dependencies' warning is preserved as it indicates a likely mistake.

Fixes streamich#755
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove warnings from useDeepCompareEffect

1 participant