Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

use-consistent-value

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

use-consistent-value

Keep a consistent reference to an object or array based on their values

  • 1.0.0
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
10K
increased by6.67%
Maintainers
1
Weekly downloads
 
Created
Source

useConsistentValue

Keep a consistent reference to an object or array based on their values. Useful when using them as dependencies of an useEffect, useMemo or useCallback hooks.

Usage

Install it

$ yarn add use-consistent-value

Import it

import useConsistentValue from 'use-consistent-value';

Use it inside a component

const [title, setState] = React.useState('');
const consistentValue = useConsistentValue({ title });
React.useEffect(() => {
  // do something with consistentValue
}, [consistentValue]);

Custom compare function

By default, useConsistentValue uses fast-deep-equal to compare the stored value and the new value, this could be configured passing a compare function as second argument of the hook, useful when you want to check a less properties to know if it changed.

const consistentValue = useConsistentValue(
  { title, ignoredOnCompare },
  (a, b) => a.title === b.title
);

The compare function must return a boolean, with true in case the values are the same and false if they are not.

FAQs

Package last updated on 09 Jun 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