Skip to content

Commit 6ec7d74

Browse files
authored
Fix example of memoizing children in README.md (react-grid-layout#1158)
The `count` variable comes from props, not as an argument to the useMemo callback.
1 parent 2bb6a26 commit 6ec7d74

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -468,9 +468,9 @@ shouldComponentUpdate(nextProps: Props, nextState: State) {
468468
If you memoize your children, you can take advantage of this, and reap faster rerenders. For example:
469469
470470
```js
471-
function MyGrid() {
472-
const children = React.useMemo((count) => {
473-
return new Array(count).fill(undefined).map((val, idx) => {
471+
function MyGrid(props) {
472+
const children = React.useMemo(() => {
473+
return new Array(props.count).fill(undefined).map((val, idx) => {
474474
return <div key={idx} data-grid={{x: idx, y: 1, w: 1, h: 1}} />;
475475
});
476476
}, [props.count]);

0 commit comments

Comments
 (0)