I am trying to load this FlatList but it is not showing anything in the screen and I am not getting errors. The breed console.log is logging an array of objects with keys of $t.
import React, { Component } from 'react';
import { FlatList, Text, View } from 'react-native';
import { connect } from 'react-redux';
import { Container, Content } from 'native-base';
// import BreedListItem from './BreedListItem';
class BreedList extends Component {
render() {
console.log(this.props.breeds.breed);
return (
<Container>
<Content>
<FlatList
style={{ flex: 1 }}
dataSource={this.props.breeds.breed}
renderItem={(breed) => {
console.log(breed.$t);
return (
<View><Text>{breed.$t}</Text></View>
);
}
}
keyExtractor={(breed) => `${breed.$t}`}
/>
</Content>
</Container>
);
}
}
const mapStateToProps = (state) => {
return {
breeds: state.breeds.breeds
};
};
export default connect(mapStateToProps)(BreedList);
The console log of this.props.breeds.breed is below.
(37) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
0
:
{$t: "Affenpinscher"}
1
:
{$t: "Afghan Hound"}
2
:
{$t: "Airedale Terrier"}
...
Meet FlashList! A FlatList alternative that runs on UI thread and, as they claim on their website, it runs 10x faster on JS and 5x faster on JS thread. Even considering only half the improvement — these are really great performance boosts. pod install if you need to replace your existing <FlatList> with <FlashList>.
Displaying a List with a React Native FlatList. The FlatList component requires two props: data and renderItem. A data prop takes an array of data that needs to be rendered, and renderItem defines a function that takes data via parameters and returns a formatted component to be displayed on the screen.
React Native RefreshControl If you're rendering a list of data using the ScrollView or FlatList component, you can use RefreshControl to add the pull-to-refresh capability. When you initiate the pull-to-refresh gesture, RefreshControl triggers an onRefresh event.
flatlist-selectableThis is a PureComponent which means that it will not re-render if props remain shallow-equal. Make sure that everything your renderItem function depends on is passed as a prop (e.g. extraData ) that is not === after updates, otherwise your UI may not update on changes.
This also happens if you forget to return something from your renderItem function. For example:
renderItem = (row, sectID, rowID) => {
<View style={{flexDirection: 'row'}}>
<Text>{row.item}</Text>
</View>;
};
As you can see the return statement is missing, but this doesn't trigger an error, warning or anything - you just get a blank Flatlist.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With