Please help me. When there is a large list, flat list is laggy and sometimes crashing app in react native .
I have tried Optimized list: it is not showing images, and i have tried react-native large list. Nothing is working.
This is the code:
{loading == false && (
<FlatList
data={this.state.data}
numColumns="2"
renderItem={({ item }) => <ExampleComponent url=
{item.media} />}
keyExtractor={(item, index) => item.itemurl}
windowSize={15}
onEndReachedThreshold={1}
onEndReached={this.handleLoadMore}
removeClippedSubviews={true}
maxToRenderPerBatch={10}
/>
)}
This is component class
import React, { PureComponent } from "react";
import { View, Text, StyleSheet, Image ,TouchableOpacity } from "react-native";
import FastImage from "react-native-fast-image";
export default class ExampleComponent extends PureComponent {
constructor(props) {
super(props);
//console.log(this.props);
}
render() {
return (
<TouchableOpacity style={styles.imageContainer}>
<View >
<FastImage
source={{
uri:this.props.url
}}
style={styles.imageStyle}
/>
</View>
</TouchableOpacity>
);
}
}
const styles = StyleSheet.create({
imageContainer: {
flex: 1,
borderWidth: 1,
borderColor: "#dedede",
borderRadius: 5,
margin: 5
},
imageStyle: {
flex: 1,
width: null,
height: 100,
borderTopLeftRadius:5,
borderTopRightRadius:5
},
});
And im getting this message in console when rows are more
This is handle load more function
handleLoadMore = () => {
console.log("Called");
if (this.state.next != 0) {
const u =
"https://url&q=" +
this.props.navigation.state.params.data +
"&pos=" +
this.state.next;
fetch(u, {
method: "GET"
})
.then(res => res.json())
.then(response => {
this.setState({
data: [...this.state.data, ...response.results],
next: response.next
});
});
}
}
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. {"dt":1098,"prevDt":684,"contentLength":6832}