You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
7kb library to change the world. It is not fast, but it is MUCH faster that VDOM tree comparison you will face in case of render trashing.
10
+
Uses [memoize-state](https://github.com/theKashey/memoize-state) underneath, providing the same magic for `get` as [immer](https://github.com/mweststrate/immer) provided to `set`.
4
11
5
-
Component memoization for React! Based on [Dan Abramov's tweet](https://twitter.com/dan_abramov/status/965378278461755392) :)
12
+
__Just write code as you want. It it will be properly memoized__.
13
+
14
+
This is declarative component memoization for React! Based on [Dan Abramov's tweet](https://twitter.com/dan_abramov/status/965378278461755392)
6
15
Could change the way you did `componentWillReceiveProps`, could replace `getDerivedStateFromProps`, could make things better.
Or, the better example (from [react-copy-write](https://github.com/aweary/react-copy-write#consuming-state))
141
+
```js
142
+
constUserAvatar= ({ id }) => (
143
+
<MemoizedRender consumer={State.Consumer}>
144
+
{state=> (
145
+
<div className="avatar">
146
+
<img src={state.users[id].avatar.src} />
147
+
</div>
148
+
)}
149
+
</MemoizedRender>
150
+
);
151
+
```
152
+
While `react-copy-write` declares that _ The problem with this is that whenever any value in state changes, UserAvatar will be re-rendered, even though it's only using a single property from a single, nested object._
153
+
This example will work, as long MemoizedRender will track used keys, and perform update only when necessary.
154
+
155
+
It is also possible to provide `value` as a prop
156
+
```js
157
+
<MemoizedRender value={originalValue}>
158
+
{values=><Render {...select(values)} />}
159
+
</MemoizeContext>
160
+
```
161
+
162
+
MemoizedRender __memoizes "render" as a whole__. This is __absolute pure component__. Be carefull. Might be not 100% compatible with async rendering
163
+
if you pass values you were provided down the tree, as long __async accessed keys are not tracked__.
164
+
Thus - MemoizedRender may not react to changes in them.
0 commit comments