react native flatlist item click code example
Example 1: flatlist onrefresh react native
const [isFetching, setIsFetching] = useState(false);
const fetchData = () => {
dispatch(getAllDataAction(userParamData));
setIsFetching(false);
};
const onRefresh = () => {
setIsFetching(true);
fetchData();
};
<FlatList
data={topics}
keyExtractor={(item) => item.id.toString()}
renderItem={renderItem}
onRefresh={onRefresh}
refreshing={isFetching}
progressViewOffset={100}
ListEmptyComponent={<Empty message="No data found." />}
/>;
Example 2: flatlist react native horizontal
<FlatList
data={this.state.newsFeed}
refreshing={this.state.refreshing}
horizontal={this.state.isHorizontal}
ref={ref => { this.newsFeedListRef = ref; }}
renderItem={this.renderNewsFeedRow.bind(this)}
keyExtractor={(item, index) => `feed_${index}`}
onRefresh={this.__handleNewsFeedOnRefresh.bind(this)}
ListHeaderComponent={this.renderListHeaderComponent.bind(this)}
getItemLayout={(data, index) => ({ index, length: ITEM_HEIGHT, offset: (ITEM_HEIGHT * index) })} />