My React-Native Flatlist have refused render data when my json data is just one. My flatlist renders properly when the data on my Json is more than one.
I have tried all the ricks i can think of but yet, its not working. This is happening to all the Flatlist in all my program and its sickining already.
I have tried getting the array side using Object.keys(jsonResponse.Product).length;
before choosing to either render to a Flatlist or return a single data View which refused to also work for me as the Object.key returns the same size when the data item is one and same when its two. (really strange)
I have also tried effecting the styling of the Flatlist my usingheight:((Dimensions.get('screen').height))
and width:((Dimensions.get('screen').width))
in the Flatlist contentContainerStyle props, yet it does not render when data is single
Also tried using Array.from()
to make sure that the data the flatlist will render is well converted to an object/array
I have also tried using this.state.PC_list_data.map()
which still does not render when the data item is just one (single) like the flatlist
JSON OUTPUT WHEN DATA IS MORE THAN ONE
render(){
return(<FlatList
contentContainerStyle={{
borderWidth: 0,
width:((Dimensions.get('screen').width)),
//height:((Dimensions.get('screen').height))+50,
borderColor:'#00d',
// marginTop:30
}}
data={ Array.from(this.state.PC_list_data) || []}
keyExtractor={(item) =>item.Product_id}
renderItem={({item,index})=>
{
return (<CategoryProduct_List
{...item}
List_index={index}
HrefNav={this.navigateToSubProduct.bind(this, {...item})}
/>
)}
}
/>)
}
///CODE ON THE CategoryProduct_List Component
const CategoryProduct_List = props =>
{
//alert('aaa')
return (<View style={[{
flex: 1,
display:'flex',
flexDirection: "row",
backgroundColor: 'rgb(243,243,243)',
marginHorizontal:10,
justifyContent:'space-between',
alignItem:'center',
borderLeftWidth:10,
borderLeftColor:'#80146D',
marginBottom:10,
marginLeft:5+'%',
marginTop:5,
padding:10,
width: 90+'%',
height:100+'%'
}]}>
<View style={{
alignItem:"left",
}}>
<TouchableOpacity
activeOpacity={0.7} onPress={()=> props.HrefNav()}>
<Text>{props.Product_name.toUpperCase()}</Text>
</TouchableOpacity>
</View>
<View style={{ alignItems: "flex-end",}}>
<TouchableOpacity
activeOpacity={0.7}>
<IconSet color='#80146D' onPress={()=> props.HrefNav()} size={25} name="arrow-forward"/>
</TouchableOpacity>
</View>
</View>);
}
export default CategoryProduct_List;
What i want to know is how i can make the Flatlist render my single records and what i am not doing right here