aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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.