-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp4.js
44 lines (37 loc) · 1004 Bytes
/
App4.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
import { View, Text, ActivityIndicator, FlatList } from 'react-native'
import React ,{useEffect,useState}from 'react'
import { Item } from 'react-navigation-header-buttons';
const App = () => {
const [isLoading,setLoading] = useState(true);
const [data,setData] = useState([]);
const getMovie = async () => {
try {
const response = fetch('https://reactnative.dev/movies.json');
const json = await response.json();
setData(json.movies)
} catch (error) {
alert(error.messgae);
} finally{
setLoading(false);
}
}
useEffect (()=>{
getMovie();
},[])
return (
<View style = {{ flex: 1, padding: 20 }}>
{ isLoading ? <ActivityIndicator/> : (
<FlatList
data={data}
keyExtractor = {({ id }, index)=> id }
renderItem = {({ item })=>(
<Text>{item.title}, {item.releaseYear}</Text>
)}
/>
)
}
<Text>App</Text>
</View>
)
}
export default App