Last active
October 13, 2017 12:48
-
-
Save guilhermepontes/a588d92bfa47aca7512c4eb1565e1435 to your computer and use it in GitHub Desktop.
react - flatList + gingle big datalist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react' | |
import { FlatList, Text } from 'react-native' | |
class ItemListView extends Component { | |
state = { | |
currentPage: 1, | |
perPage: 3, | |
items: [ | |
{ name: 'A', id: 1 }, { name: 'B', id: 2 }, { name: 'C', id: 3 }, | |
{ name: 'D', id: 4 }, { name: 'E', id: 5 }, { name: 'F', id: 6 }, | |
{ name: 'G', id: 7 }, { name: 'H', id: 8 }, { name: 'I', id: 9 }, | |
] | |
} | |
render() { | |
const { items, perPage, currentPage } = this.state | |
const data = items.slice(0, perPage * currentPage) | |
return ( | |
<FlatList | |
data={data} | |
keyExtractor={item => item.id} | |
onEndReachedThreshold={0.5} | |
onEndReached={() => this.setState({ currentPage: currentPage + 1 })} | |
renderItem={({ item }) => <Text style={{ padding: 50 }}>{ item.name }</Text>} /> | |
) | |
} | |
} | |
export default ItemListView |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment