diff options
author | Jamie Kyle <me@thejameskyle.com> | 2019-05-29 03:00:59 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-29 03:00:59 +0300 |
commit | aecd4dd0d6394051da05b545704205ad88cba0fd (patch) | |
tree | d2660ea69a12876dafe8a20c5c068719fa07b875 | |
parent | 73164696df42aa9df9eb05c8d3f6982ff92a06ec (diff) |
Update README.md
-rw-r--r-- | README.md | 30 |
1 files changed, 30 insertions, 0 deletions
@@ -501,6 +501,36 @@ function CounterDisplay(props) { } ``` +#### 4) Wrapping your elements with `useMemo()` + +[via Dan Abramov](https://github.com/facebook/react/issues/15156#issuecomment-474590693) + +**Before:** + +```js +function CounterDisplay(props) { + let counter = Counter.useContainer() + let count = counter.count + + return ( + <p>You clicked {count} times</p> + ) +} +``` + +**After:** + +```js +function CounterDisplay(props) { + let counter = Counter.useContainer() + let count = counter.count + + return useMemo(() => ( + <p>You clicked {count} times</p> + ), [count]) +} +``` + ## Relation to Unstated I consider this library the spiritual successor to [Unstated](https://github.com/jamiebuilds/unstated). I created Unstated because I believed that React was really great at state management already and the only missing piece was sharing state and logic easily. So I created Unstated to be the "minimal" solution to sharing React state and logic. |