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

use-memo-value

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

use-memo-value

Reuse the previous version of a value unless it has changed

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
489
decreased by-83.88%
Maintainers
1
Weekly downloads
 
Created
Source

useMemoValue()

Reuse the previous version of a value unless it has changed

Install

npm install --save-dev use-memo-value

Usage

If you don't know all the members of an object, you may want to use a "shallow compare" to memoize the value so you can rely on React's referential equality (such as in useEffect(..., deps)).

import useMemoValue from "use-memo-value"

function MyComponent(props) {
  let rawParams = getCurrentUrlQueryParams() // we don't know the shape of this object
  let memoizedParams = useMemoValue(rawParams)

  useEffect(() => {
    search(memoizedParams)
  }, [memoizedParams])

  // ...
}

Note: If you know the shape of your object, you are likely better off not using this library.

If you need to customize how the values are compared, you can pass a comparator as a second argument:

let memoizedValue = useMemoValue(rawValue, (nextValue, previousValue) => {
  return Object.is(a, b) // or whatever
})

The comparator will not be called until there's a new value.

Keywords

FAQs

Package last updated on 21 Apr 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