-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathApp.js
45 lines (41 loc) · 979 Bytes
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import React, {useEffect, useState} from 'react';
import {FlatList, SafeAreaView, StyleSheet, Image} from 'react-native';
const BASE_URI = 'https://source.unsplash.com/random?sig=';
const App = () => {
const [data, setDate] = useState([]);
useEffect(() => {
fetchMore();
}, []);
const fetchMore = () => {
setDate(prevState => [
...prevState,
...Array.from({length: 20}).map((_, i) => i + 1 + prevState.length),
]);
};
return (
<SafeAreaView>
<FlatList
data={data}
style={styles.list}
numColumns={3}
onEndReached={fetchMore}
keyExtractor={e => e}
renderItem={({item}) => (
<Image source={{uri: BASE_URI + item}} style={styles.item} />
)}
/>
</SafeAreaView>
);
};
const styles = StyleSheet.create({
list: {
width: '100%',
backgroundColor: '#000',
},
item: {
aspectRatio: 1,
width: '100%',
flex: 1,
},
});
export default App;