react-native: VirtualizedList: You have a large list that is slow to update - make sure your renderItem function renders components that follow React performance best practices like PureComponent, shouldComponentUpdate, etc.
Please help, i have RN Application that fetch data to server paginately, every time scroll has end to bottom i call getMore function and get next offset to server then result of next offset i’ve been merged with list state
- On FlatList i’ve implement React PureComponent on Rendering ListItem but always have notice VirtualizedList: You have a large list that is slow to update - make sure your renderItem function renders components that follow React performance best practices like PureComponent, shouldComponentUpdate, etc.
- I’ve implement any other performance options but nothing change
- My data list scenario is fetching to api server that give partial or limit rows using cursor pagination by PRISMA JS, every i got EndReach bottom i call function getMore that will trigger to change cursor state and load more data from server then i merge that result on existing list
Expected Results
How i can remove that warning ?
`
const Tags = () => {
const navigation = useNavigation();
const mounted = useRef(false);
const [loader, setLoader] = useState(false);
const [cursor, setCursor] = useState(0);
const [list, setList] = useState([]);
const renderItem = ({item}) => <ListItem title={item.tag} />;
const getMore = () => {
setCursor(list[list.length - 1].id);
};
useEffect(() => {
mounted.current = true;
const getList = async () => {
try {
setLoader(true);
const data = await fetchList({cursor});
setList(prevState => [...prevState, ...data]);
} catch (error) {
ToastAndroid.showWithGravity(error, 3000, ToastAndroid.BOTTOM);
} finally {
setTimeout(() => {
if (mounted.current) {
setLoader(false);
}
}, 1000);
}
};
getList();
return () => {
mounted.current = false;
};
}, [cursor]);
return (
<View style={styles.container}>
<FlatList
refreshing={loader}
data={list}
renderItem={renderItem}
keyExtractor={item => item.id}
ListEmptyComponent={NoData}
showsVerticalScrollIndicator={false}
ListFooterComponent={loader ? <MoreLoader /> : null}
ItemSeparatorComponent={ListSeparator}
onEndReachedThreshold={0.5}
onEndReached={getMore}
/>
<AddButton />
</View>
);
};
// List Component
class ListItem extends PureComponent {
render() {
const {title} = this.props;
return (
<Pressable style={styles.container} android_ripple={rippleConfig}>
<View style={styles.listIconWrapper}>
<AntIcon name="folder1" style={styles.listIcon} />
</View>
<View style={styles.listContentWrapper}>
<Text numberOfLines={2} ellipsizeMode="tail">
{title}
</Text>
</View>
</Pressable>
);
}
}
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 2
- Comments: 21
I face this issue when there’s an image inside my renderItem component even i’m using memo.
further looking back at my code, I found this component is defined inside another arrow function and it is the root cause of the warning. Each time, when the parent component renders, a new instance of this function is created, and that throws the warning (I thought).
Instead of that, I split the code out and call like this
and the warning’s gone. It’s been years for my case, but hope this may be helpful for anyone facing a situation like this
Hi, i solved the problem with similar resolution using memo and give second parameter with (prevProps, nextProps) to be compared. here is my working code.
I solved this issue probably. The hint is official documents here. My example code is above. Finally, all of movements were so smoothly changed. In my case, I use
React.memo
andarePropsEqual
(2nd parameter).https://react.dev/reference/react/memo#reference
can u explain code
Same here