Skip to content

Remove warnings from useDeepCompareEffect #755

Description

@geraldarthurdavis

Is your feature request related to a problem? Please describe.

useDeepCompareEffect gives warnings when using it with primitive dependencies. This is frustrating for the common case where dependencies could either undefined or an object that you'd like to be deep-compared.

Describe the solution you'd like

Remove warnings from useDeepCompareEffect or provide a way to suppress warnings.

Activity

  1. xobotyi commented on Nov 6, 2019

    @xobotyi
    Contributor

    Any example?

  2. geraldarthurdavis commented on Nov 7, 2019

    @geraldarthurdavis
    Author
    import React from "react";
    import { useDeepCompareEffect } from "react-use";
    
    export const useObjectDidChange = <T extends any>(didChange: () => void, dep: T) => {
       useDeepCompareEffect(() => {
        didChange();
       }, [dep]);
    }
    
    function App = () => {
      const [obj, setObj] = useState<object | undefined>(undefined);
      useObjectDidChange(() => console.log("obj changed"), obj);
      
      return <div />;
    }

    This code will log a warning whenever obj is set to undefined.

  3. geraldarthurdavis commented on Nov 7, 2019

    @geraldarthurdavis
    Author

    I understand that the warning is there to help users. We should be using useEffect when the values of the dependency array are primitives. However, it's possible for the values of the array to change from primitive to non-primitive (as shown above). In that case, there should be no warning. It is correct to use useDeepCompareEffect if the value of the dependency is either a primitive or a non-primitive.

    That warning is only valid if it is always primitive.

  4. geraldarthurdavis commented on Feb 12, 2020

    @geraldarthurdavis
    Author

    If the above case doesn't satisfy you, I'd at least add the option to hide warnings from react-use. Warnings are definitely useful and I appreciate that they're in react-use. However, they clutter the console and, in this case, I simply don't agree with the warning but would still like to continue using react-use.

  5. streamich commented on Feb 15, 2020

    @streamich
    Owner

    @garrettmaring I agree, I think the warnings for primitives in useDeepCompareEffect (and shallow compare) should be removed.

  6. streamich commented on Feb 15, 2020

    @streamich
    Owner

    But the other warning about no dependencies should probably stay.

  7. tusharkrbarman commented on Jan 30, 2023

    @tusharkrbarman

    Is this issue open? Can anyone assign this to me?

  8. shrutipandya3 commented on Oct 28, 2025

    @shrutipandya3

    Can I work on this if still open?

  9. added 6 commits that reference this issue on Dec 23, 2025
    3c6909c
    4d1aa18
    95e5e84
    0eb85b5
    f11a686
    f2d6a2d
  10. added a commit that references this issue on Jan 3, 2026
    036a638
  11. added 2 commits that reference this issue on Jul 6, 2026
    334bd8c
    83ff425
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomershelp wantedExtra attention is needed

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions