Blame view

天文台pc/tianwentai-ui/node_modules/@emotion/weak-memoize/README.md 740 Bytes
bc518174   王天杨   提交两个项目文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
  # @emotion/weak-memoize
  
  > A memoization function that uses a WeakMap
  
  ## Install
  
  ```bash
  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.
  
  ```jsx
  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
  ```