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:
Am I in the right direction to solve that warning?
How to get rid of that
TypeError: renderItem is not a function ...
error?