1
0
Fork 0
react-playground/node_modules/@emotion/weak-memoize
2025-08-25 17:46:11 +02:00
..
dist worked on GarageApp stuff 2025-08-25 17:46:11 +02:00
src worked on GarageApp stuff 2025-08-25 17:46:11 +02:00
LICENSE worked on GarageApp stuff 2025-08-25 17:46:11 +02:00
package.json worked on GarageApp stuff 2025-08-25 17:46:11 +02:00
README.md worked on GarageApp stuff 2025-08-25 17:46:11 +02:00

@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