aboutsummaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
authorJamie Kyle <me@thejameskyle.com>2019-05-29 03:00:59 +0300
committerGitHub <noreply@github.com>2019-05-29 03:00:59 +0300
commitaecd4dd0d6394051da05b545704205ad88cba0fd (patch)
treed2660ea69a12876dafe8a20c5c068719fa07b875 /README.md
parent73164696df42aa9df9eb05c8d3f6982ff92a06ec (diff)
Update README.md
Diffstat (limited to 'README.md')
-rw-r--r--README.md30
1 files changed, 30 insertions, 0 deletions
diff --git a/README.md b/README.md
index 1bbe281..39e159a 100644
--- a/README.md
+++ b/README.md
@@ -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.