@emotion/weak-memoize (0.4.0)
Published 2026-02-24 13:49:19 +00:00 by atheaadmin
Installation
@emotion:registry=npm install @emotion/weak-memoize@0.4.0"@emotion/weak-memoize": "0.4.0"About this package
@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
Dependencies
Development Dependencies
| ID | Version |
|---|---|
| @definitelytyped/dtslint | 0.0.112 |
| typescript | ^5.4.5 |