1- import React , { useEffect , useRef , useState } from 'react' ;
1+ import React , { useEffect , useMemo , useRef , useState } from 'react' ;
22import { FlatList , I18nManager , StyleSheet , Text , TouchableOpacity , View } from 'react-native' ;
33
44import { UploadProgressIndicator } from './UploadProgressIndicator' ;
@@ -213,7 +213,7 @@ const FileUploadPreviewWithContext = <
213213 } ,
214214 } = useTheme ( ) ;
215215
216- const renderItem = ( { index , item } : { index : number ; item : FileUpload } ) => {
216+ const renderItem = ( { item } : { item : FileUpload } ) => {
217217 const indicatorType = getIndicatorTypeForFileState ( item . state , enableOfflineSupport ) ;
218218 const isAudio = item . file . mimeType ?. startsWith ( 'audio/' ) ;
219219
@@ -229,7 +229,7 @@ const FileUploadPreviewWithContext = <
229229 { isAudio && isSoundPackageAvailable ( ) ? (
230230 < AudioAttachmentUploadPreview
231231 hideProgressBar = { true }
232- item = { { ... item , id : index . toString ( ) } }
232+ item = { item }
233233 onLoad = { onLoad }
234234 onPlayPause = { onPlayPause }
235235 onProgress = { onProgress }
@@ -300,9 +300,18 @@ const FileUploadPreviewWithContext = <
300300 }
301301 } , [ fileUploadsLength ] ) ;
302302
303+ const memoizedFilesToDisplay = useMemo (
304+ ( ) =>
305+ filesToDisplay . map ( ( file , index ) => ( {
306+ ...file ,
307+ id : index . toString ( ) ,
308+ } ) ) ,
309+ [ filesToDisplay ] ,
310+ ) ;
311+
303312 return fileUploadsLength ? (
304313 < FlatList
305- data = { filesToDisplay }
314+ data = { memoizedFilesToDisplay }
306315 getItemLayout = { ( _ , index ) => ( {
307316 index,
308317 length : FILE_PREVIEW_HEIGHT + 8 ,
0 commit comments