A memoization function that uses a WeakMap


13,5171450.2.52 years ago3 years agoMinified + gzip package size for @emotion/weak-memoize in KB



A memoization function that uses a WeakMap


yarn add @emotion/weak-memoize


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

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.