React Native doesn't render all item?
See original GitHub issuePlease provide all the information requested. Issues that do not follow this format are likely to stall.
Description
I tried many way but the flatlist never load full item on my api.Im my api i have 16 item to load but app only load 10 item.
React Native version:
react-native 0.63.3
Snack, code example, screenshot, or link to a repository:
import React, {useState, useEffect} from 'react';
import {
View,
Text,
StyleSheet,
FlatList,
Image,
TouchableOpacity,
Pressable,
ActivityIndicator,
VirtualizedList,
} from 'react-native';
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome';
import {faPrescriptionBottle} from '@fortawesome/free-solid-svg-icons';
import {faMapMarkerAlt} from '@fortawesome/free-solid-svg-icons';
import {faIndustry} from '@fortawesome/free-solid-svg-icons';
import AsyncStorage from '@react-native-community/async-storage';
const Mainscreen = ({navigation}) => {
const [warehouse, setWarehouse] = useState([]);
const [pageCurrent, setPageCurrent] = useState(1);
const [isLoading, setIsLoading] = useState(false);
useEffect(() => {
let isMounted = true;
setIsLoading(true);
fetchData();
return () => {
isMounted = false;
};
}, [pageCurrent]);
const fetchData = async () => {
const token = await AsyncStorage.getItem('idtoken');
const apiURL =
'https://cnpmwarehouse.herokuapp.com/warehouses/user?limit=2&page=' +
pageCurrent;
await fetch(apiURL, {
method: 'GET',
headers: {
accept: 'application/json',
Authorization: `Bearer ${token}`,
},
})
.then((response) => response.json())
.then((responseJson) => {
setWarehouse(warehouse.concat(responseJson.data.warehouses));
setIsLoading(false);
});
};
renderItem = ({item}) => {
return (
<Pressable
onPress={() => {
navigation.navigate('Detail', {
idwarehouse: item.id,
});
}}>
<View style={styles.card}>
<Image
style={styles.tinyLogo}
source={require('../assets/images/blakcstonemain.jpg')}
/>
<View style={{marginTop: 15}}>
<View style={styles.info}>
<FontAwesomeIcon
style={styles.icon}
icon={faIndustry}
size={25}
/>
<Text numberOfLines={3} style={styles.text}>
{item.name}
</Text>
</View>
<View style={styles.info}>
<FontAwesomeIcon
style={styles.icon}
icon={faMapMarkerAlt}
size={25}
/>
<Text numberOfLines={3} style={styles.text}>
{item.address}
</Text>
</View>
<View style={styles.info}>
<FontAwesomeIcon
style={styles.icon}
icon={faPrescriptionBottle}
size={25}
/>
<Text numberOfLines={3} style={styles.text}>
{item.description}
</Text>
</View>
</View>
</View>
</Pressable>
);
};
handleFooter = () => {
return isLoading ? (
<View style={styles.loader}>
<ActivityIndicator size="small" color="red" />
</View>
) : null;
};
handleLoadMore = () => {
setPageCurrent(pageCurrent + 1);
setIsLoading(true);
};
return (
<>
<View style={styles.container}>
<FlatList
data={warehouse}
numColumns={1}
keyExtractor={(item) => item.id.toString()}
initialNumToRender={16}
//debug={true}
renderItem={renderItem}
updateCellsBatchingPeriod={100}
ListFooterComponent={handleFooter}
onEndReached={handleLoadMore}
onEndReachedThreshold={10}
/>
</View>
</>
);
};
const styles = StyleSheet.create({
container: {
//flex: 1,
paddingTop: 15,
paddingHorizontal: 15,
backgroundColor: 'white',
},
card: {
height: 300,
backgroundColor: '#fff',
alignItems: 'flex-start',
marginBottom: 30,
elevation: 20,
borderRadius: 15,
overflow: 'hidden',
},
tinyLogo: {
width: 400,
height: 150,
},
icon: {
color: '#FC4646',
},
text: {
fontFamily: 'Roboto-BoldItalic',
fontSize: 20,
marginLeft: 15,
},
info: {
flexDirection: 'row',
marginBottom: 10,
marginHorizontal: 20,
},
loader: {
marginTop: 10,
alignItems: 'center',
},
});
export default Mainscreen;
Issue Analytics
- State:
- Created 3 years ago
- Comments:6
Top Results From Across the Web
React-Native Flatlist RenderItem doesn't render - Stack Overflow
1. Initially the ayet state is a string, then after the GET request, it's an object. I'm fairly certain that the FlatList component...
Read more >Large Flatlist is not rendering all items #15990 - GitHub
Hi, I'm running react-native v0.52.8 and I have the same issue. Will this be fixed? or we have to use third party components?...
Read more >FlatList - React Native
A performant interface for rendering basic, flat lists, supporting the most handy features:
Read more >Hooks FAQ - React
Do Hooks cover all use cases for classes? Do Hooks replace render props and higher-order components? What do Hooks mean for popular APIs...
Read more >When does React re-render components? - Felix Gerschau
This doesn't only mean the component's render function will be called, but also that all its subsequent child components will re-render, ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Can you try to put warehouse in eval?
<FlatList data={(warehouse)} numColumns={1} keyExtractor={(item) => item.id.toString()} initialNumToRender={16} //debug={true} renderItem={renderItem} updateCellsBatchingPeriod={100} ListFooterComponent={handleFooter} onEndReached={handleLoadMore} onEndReachedThreshold={10} />
Please share your code and let us review.