From aecd4dd0d6394051da05b545704205ad88cba0fd Mon Sep 17 00:00:00 2001 From: Jamie Kyle Date: Tue, 28 May 2019 17:00:59 -0700 Subject: Update README.md --- README.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) 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 ( +

You clicked {count} times

+ ) +} +``` + +**After:** + +```js +function CounterDisplay(props) { + let counter = Counter.useContainer() + let count = counter.count + + return useMemo(() => ( +

You clicked {count} times

+ ), [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. -- cgit v1.2.3