Skip to content

Commit

Permalink
fix: memo image
Browse files Browse the repository at this point in the history
  • Loading branch information
zirong.cai committed May 8, 2024
1 parent 4797e19 commit e1d9c15
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 13 deletions.
43 changes: 43 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,9 @@
"bugs": {
"url": "https://github.com/benhowell/react-grid-gallery/issues"
},
"homepage": "https://benhowell.github.io/react-grid-gallery/"
"homepage": "https://benhowell.github.io/react-grid-gallery/",
"dependencies": {
"@types/lodash-es": "^4.17.12",
"lodash-es": "^4.17.21"
}
}
18 changes: 6 additions & 12 deletions src/Image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { CheckButton } from "./CheckButton";
import { ImageExtended, ImageProps } from "./types";
import * as styles from "./styles";
import { getStyle } from "./styles";
import isEqual from "lodash-es/isEqual";

const imagePropsAreEqual = (prevProps: ImageProps, currProps: ImageProps) => {
// states are the same iff the props are the same

const {
item: prevItem,
index: prevIndex,
Expand All @@ -24,17 +24,11 @@ const imagePropsAreEqual = (prevProps: ImageProps, currProps: ImageProps) => {
} = currProps;

return (
prevItem.src === currItem.src &&
prevItem.width === currItem.width &&
prevItem.height === currItem.height &&
prevItem.scaledHeight === currItem.scaledHeight &&
prevItem.scaledWidth === currItem.scaledWidth &&
prevItem.viewportWidth === currItem.viewportWidth &&
prevItem.marginLeft === currItem.marginLeft &&
prevIndex === currIndex &&
prevMargin === currMargin &&
prevHeight === currHeight &&
prevIsSelectable === currIsSelectable
isEqual(prevItem, currItem) &&
isEqual(prevIndex, currIndex) &&
isEqual(prevMargin, currMargin) &&
isEqual(prevHeight, currHeight) &&
isEqual(prevIsSelectable, currIsSelectable)
);
};

Expand Down

0 comments on commit e1d9c15

Please sign in to comment.