0

I am using FlatList. I have a function to render item:

const renderItem = ({item}) => {
    return (
      <ListItem
        ...
      />
    );
  };

My FlatList uses above renderItem function to render item, it is like:

   const MyScreen = () => {
    // here is the above renderItem function
    const renderItem = ({item}) => {...}
    ...
    return (
       <View>
         <FlatList
           ...
           renderItem={renderItem}
         />
       </View>)
    }

When I run the app, it works, but when I load more items from backend for the list, I get warning:

VirtualizedList: You have a large list that is slow to update - make sure your renderItem function renders components that follow React performance best practices

I want to solve this warning, I tried using React.memo() api, by wrapping the renderItem function like this:

   const MyScreen = () => {
    // here is the above renderItem function
    const renderItem = ({item}) => {...}
    ...
    return (
       <View>
         <FlatList
           ...
           renderItem={React.memo(renderItem)}
         />
       </View>)
    }

When I run the app again, it crashes with error:

TypeError: renderItem is not a function. (In 'renderItem(props)', 'renderItem' is an instance of Object)

So, my questions are:

  1. Am I in the right direction to solve that warning?

  2. How to get rid of that TypeError: renderItem is not a function ... error?

Leem.fin
  • 35,699
  • 70
  • 166
  • 297
  • https://stackoverflow.com/questions/44743904/virtualizedlist-you-have-a-large-list-that-is-slow-to-update maybe this helps? – Alireza tk Oct 07 '20 at 15:43

0 Answers0