New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

use-custom-compare

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

use-custom-compare

It's React's useEffect/useMemo/useCallback hooks, except using custom comparison on the inputs, not reference equality

  • 1.0.11
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
16K
decreased by-0.39%
Maintainers
1
Weekly downloads
 
Created
Source

use-custom-compare

It's React's useEffect/useMemo/useCallback hooks, except using custom comparison on the inputs, not reference equality

License Actions Status NPM Version Downloads Month Downloads Total Dependencies Status Semantic Release Commitizen Friendly PRs Welcome

All Contributors

Installation

npm install use-custom-compare

# or

yarn add use-custom-compare

Usage

useCustomCompareEffect

import React from "react";
import { useCustomCompareEffect } from "use-custom-compare";
import isEqual from "lodash/isEqual";

function App({ options }) {
  useCustomCompareEffect(
    () => {
      // do something significant here
      return () => {
        // return to clean up that significant thing
      };
    },
    [options],
    (prevDeps, nextDeps) => isEqual(prevDeps, nextDeps)
  );

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

useCustomCompareCallback

import React from "react";
import { useCustomCompareCallback } from "use-custom-compare";
import isEqual from "lodash/isEqual";

function App({ options }) {
  const memoized = useCustomCompareCallback(
    () => {
      // do something significant here
    },
    [options],
    (prevDeps, nextDeps) => isEqual(prevDeps, nextDeps)
  );

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

useCustomCompareMemo

import React from "react";
import { useCustomCompareMemo } from "use-custom-compare";
import isEqual from "lodash/isEqual";

function App({ options }) {
  const memoized = useCustomCompareMemo(
    () => {
      // do something significant here
    },
    [options],
    (prevDeps, nextDeps) => isEqual(prevDeps, nextDeps)
  );

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

Contributing

Contributions are always welcome! Please read the contributing first.

Inspiration

  • use-deep-compare-effect 🐋 It's react's useEffect hook, except using deep comparison on the inputs, not reference equality.
  • use-deep-compare It's react's useEffect/useMemo/useCallback hooks, except using deep comparison on the inputs.
  • use-custom-compare-effect useEffect hook which takes a comparison function instead of compare using reference equality.

Contributors

Thanks goes to these wonderful people (emoji key):


Kotaro Sugawara

💻 📖 🤔 🚇 ⚠️

This project follows the all-contributors specification. Contributions of any kind welcome!

License

MIT © Kotaro Sugawara

Keywords

FAQs

Package last updated on 10 Dec 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc