Skip to content

Commit

Permalink
fix(messenger-feed): resolve unnecessary image reloads by memoizing f…
Browse files Browse the repository at this point in the history
…unctions in media rendering (#2278)
  • Loading branch information
domw30 committed Sep 13, 2024
1 parent 50c4ee3 commit 0ad0524
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/components/messenger/feed/components/post/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ export const Post = ({
[text]
);

const handleImageLoad = (event: React.SyntheticEvent<HTMLImageElement>) => {
const handleImageLoad = useCallback((event: React.SyntheticEvent<HTMLImageElement>) => {
const { naturalWidth: width, naturalHeight: height } = event.currentTarget;
handleMediaAspectRatio(width, height);
setIsImageLoaded(true);
};
}, []);

const handleMediaAspectRatio = (width: number, height: number) => {
const aspectRatio = width / height;
Expand All @@ -72,11 +72,11 @@ export const Post = ({
return { width: finalWidth, height: finalHeight };
};

const getPlaceholderDimensions = (w: number, h: number) => {
const getPlaceholderDimensions = useCallback((w: number, h: number) => {
const maxWidth = 420;
const maxHeight = 520;
return handlePlaceholderAspectRatio(w, h, maxWidth, maxHeight);
};
}, []);

const renderMedia = useCallback(
(media) => {
Expand Down

0 comments on commit 0ad0524

Please sign in to comment.