From f72fcd4f08eefdef2e94770a102781f580536056 Mon Sep 17 00:00:00 2001 From: Avinash Lingaloo Date: Fri, 10 Jun 2022 17:40:14 +0400 Subject: [PATCH] useMemo function call (#6372) --- app/components/post_list/post/body/files/image_file.tsx | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/app/components/post_list/post/body/files/image_file.tsx b/app/components/post_list/post/body/files/image_file.tsx index dab45fe003..0831f2eeab 100644 --- a/app/components/post_list/post/body/files/image_file.tsx +++ b/app/components/post_list/post/body/files/image_file.tsx @@ -1,7 +1,7 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -import React, {useCallback, useEffect, useState} from 'react'; +import React, {useCallback, useMemo, useState} from 'react'; import {StyleProp, StyleSheet, useWindowDimensions, View, ViewStyle} from 'react-native'; import LinearGradient from 'react-native-linear-gradient'; @@ -82,7 +82,7 @@ const ImageFile = ({ const dimensions = useWindowDimensions(); const theme = useTheme(); const serverUrl = useServerUrl(); - const [isGif, setIsGif] = useState(isGifImage(file)); + const isGif = useMemo(() => isGifImage(file), [file]); const [failed, setFailed] = useState(false); const style = getStyleSheet(theme); let image; @@ -117,10 +117,6 @@ const ImageFile = ({ return props; }; - useEffect(() => { - setIsGif(isGifImage(file)); - }, [file]); - if (file.height <= SMALL_IMAGE_MAX_HEIGHT || file.width <= SMALL_IMAGE_MAX_WIDTH) { let wrapperStyle: StyleProp = style.fileImageWrapper; if (isSingleImage) {