Created
June 24, 2023 14:01
-
-
Save Bound3R/4421d1ee48d88936b24e1038684a8815 to your computer and use it in GitHub Desktop.
session 24/6
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, { useState, useEffect } from 'react'; | |
import { StyleSheet, Text, View, ScrollView, FlatList } from 'react-native'; | |
import axios from 'axios'; | |
import { Card } from 'react-native-paper'; | |
import { FlashList } from "@shopify/flash-list"; | |
export default function App() { | |
const [loading, setLoading] = useState(true); | |
const [data, setData] = useState([]); | |
const getData = () => { | |
// fetch usgin api | |
axios.get('https://jsonplaceholder.typicode.com/posts').then((response) => { | |
setData(response.data); | |
}).catch((err) => { | |
console.log(err); | |
}); | |
setLoading(false); | |
} | |
useEffect(() => { | |
getData() | |
}) | |
return ( | |
<View style={styles.container}> | |
<Text style={styles.title}>List of Posts</Text> | |
<View> | |
{loading ? ( | |
<Text>Loading...</Text> | |
) : ( | |
<FlashList | |
data={data} | |
estimatedItemSize={100} | |
keyExtractor={({ id }, index) => id} | |
renderItem={({ item }) => ( | |
<Text style={styles.item}>{item.title}</Text> | |
)} | |
/> | |
) | |
} | |
</View> | |
</View> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment