1. @emotion/weak-memoize
A memoization function that uses a WeakMap
@emotion/weak-memoize
Package: @emotion/weak-memoize
Created by: emotion-js
Last modified: Sat, 06 May 2023 08:49:17 GMT
Version: 0.3.1
License: MIT
Downloads: 45,124,020
Repository: https://github.com/emotion-js/emotion

Install

npm install @emotion/weak-memoize
yarn add @emotion/weak-memoize

@emotion/weak-memoize

A memoization function that uses a WeakMap

Install

 yarn add @emotion/weak-memoize

Usage

Because @emotion/weak-memoize uses a WeakMap the argument must be a non primitive type, e.g. objects, functions, arrays and etc. The function passed to weakMemoize must also only accept a single argument.

 import weakMemoize from '@emotion/weak-memoize'

let doThing = weakMemoize(({ someProperty }) => {
  return { newName: someProperty }
})

let obj = { someProperty: true }

let firstResult = doThing(obj)

let secondResult = doThing(obj)

firstResult === secondResult // true

let newObj = { someProperty: true }

let thirdResult = doThing(newObj)

thirdResult === firstResult // false

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code