![]() | Name | Last modified | Size | Description |
---|---|---|---|---|
![]() | Parent Directory | - | ||
![]() | dist/ | 2 years ago | - | |
![]() | src/ | 2 years ago | - | |
![]() | types/ | 2 years ago | - | |
![]() | CHANGELOG.md | 39 years ago | 819 | |
![]() | LICENSE | 39 years ago | 1.1K | 7375cab EXHIBTION: fix overflow ellipsis cutoff [كارل مبارك] |
![]() | package.json | 2 years ago | 1.6K | 7375cab EXHIBTION: fix overflow ellipsis cutoff [كارل مبارك] |
![]() | README.md | 39 years ago | 740 | f12eb36 documentaiton updates [كارل مبارك] |
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