Skip to content

Commit

Permalink
update README
Browse files Browse the repository at this point in the history
  • Loading branch information
dai-shi committed Nov 1, 2020
1 parent a2888c1 commit 046f24f
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,21 @@ Instead of [reselect](https://github.com/reduxjs/reselect).
```js
import { useSelector } from 'react-redux';

const selectTotal = memoize(({ state, id }) => ({
total: state.a + state.b,
title: state.titles[id]
}))
const getScore = memoize(state => ({
score: heavyComputation(state.a + state.b),
createdAt: Date.now(),
}));

const Component = ({ id }) => {
const { total, title } = useSelector(state => selectTotal({ state, id }));
return <div>{total} {title}</div>;
const { score, title } = useSelector(useCallback(memoize(state => ({
score: getScore(state),
title: state.titles[id],
})), [id]));
return <div>{score.score} {score.createdAt} {title}</div>;
};
```

[CodeSandbox](https://codesandbox.io/s/proxy-memoize-demo-c1021)
- [CodeSandbox 1](https://codesandbox.io/s/proxy-memoize-demo-c1021)

## Usage with Zustand

Expand Down

0 comments on commit 046f24f

Please sign in to comment.