1.2.1 • Published 5 months ago

use-deep-compare v1.2.1

Weekly downloads
11,212
License
MIT
Repository
github
Last release
5 months ago

Use Deep Compare

npm npm NpmLicense

Use Deep Compare - React hooks, except using deep comparison on the inputs, not reference equality. Read about Hooks feature.

Installation

Note: React 16.8+ is required for Hooks.

With npm

npm i use-deep-compare

Or with yarn

yarn add use-deep-compare

Usage

useDeepCompareEffect

import React from "react";
import { useDeepCompareEffect } from "use-deep-compare";

function App({ object, array }) {
  useDeepCompareEffect(() => {
    // do something significant here
    return () => {
      // return to clean up that significant thing
    };
  }, [object, array]);

  return <div>{/* render significant thing */}</div>;
}

useDeepCompareCallback

import React from "react";
import { useDeepCompareCallback } from "use-deep-compare";

function App({ object, array }) {
  const callback = useDeepCompareCallback(() => {
    // do something significant here
  }, [object, array]);

  return <div>{/* render significant thing */}</div>;
}

useDeepCompareMemo

import React from "react";
import { useDeepCompareMemo } from "use-deep-compare";

function App({ object, array }) {
  const memoized = useDeepCompareMemo(() => {
    // do something significant here
  }, [object, array]);

  return <div>{/* render significant thing */}</div>;
}

react-hooks/exhaustive-deps eslint warnings

To receive eslint warnings about missing array dependencies, just like for standard useEffect, useCallback, useMemo hooks - extend you eslint config as follows:

{
  "rules": {
    // ...
    "react-hooks/exhaustive-deps": ["warn", {
      "additionalHooks": "(useDeepCompareEffect|useDeepCompareCallback|useDeepCompareMemo)"
    }]
  }
}

Credits

@taze-editor/core@infinitebrahmanuniverse/nolb-use-d@everything-registry/sub-chunk-3025@gisce/react-formiga-table@indexdata/harvester-admin@maktouch/use-popper@hazelcast/ui@mturley-latest/react-table-batteries@ohs/use-progressive-imageplasmic-supabasepontx-semix-formsemix-form-rendertc-create-appsimple-text-editor-rclste-react-coretranslation-helps-print-preview-rclproskomma-react-hooksrn-collapsible-tab-viewrn-collapsible-tab-view-scrollablereact-native-airone-tabviewreact-native-collapsible-with-infinite-scrollreact-native-collapsible-tab-viewreact-native-openai-jsxreact-native-readiumreact-native-tab-adasiuse-popperuse-dispatch-actionuse-typed-event-listenerzum-plate-core@watheia/micro.base-ui.hooks.use-graphql-light@ahmetkuslular/react-native-collapsible-tab-view@securityscorecard/design-systemfont-detect-rhl@nilscox/graphviz-react@modern-js-block/container-activity@modern-js-block/g2plot@modern-js-block/antd-atomic-components@modern-js-block/arco-atomic-components@mediamonks/use-popper@meta-ui/runtime@taze-editor/taze-core@teambit/base-ui.hooks.use-graphql-light@waweb/base-ui.hooks.use-graphql-light@waweb/compendium.base-ui.hooks.use-graphql-light@watheia/tools.hooks.use-graphql-light@rdub/react-sql.js-httpvfs@regraph-ai/client@regraph-ai/frontend@xelah/core@xelah/type-perf-html@sunmao-ui-fork/runtime@sunmao-ui/runtime@ster/core@subscan/widget-runtimegitea-react-toolkit@weaveworksoss/backstage-plugin-flux@zhangrh1101/react-native-collapsible-tab-view@virtual-grid/react@udecode/plate-core@watheia/design.ui.hooks.use-graphql-light@watheia/app.ui.hooks.use-graphql-light@watheia/base-ui.design.system.guide@watheia/base-ui.extensions.sapper-mfe@watheia/base-ui.hooks.use-graphql-lighthooks-view-model@watheia/iron-ui.hooks.use-graphql-light@cherry-pie/react@9troisquarts/ant-formbetter-plate-corekep-plate-coredragonfly-v@ediri/backstage-plugin-flux@edygar/use-requestdatocms-plugin-web-previewsdatocms-plugin-table-editordatocms-plugin-complex-table-editorannouncekit-react-native@carlosthe19916-latest/react-table-batteries@flowes/plate-core
1.2.1

5 months ago

1.2.0

5 months ago

1.1.0

4 years ago

1.0.0

4 years ago

0.1.0

5 years ago

0.0.1

5 years ago

0.0.0

5 years ago