Skip to content

Instantly share code, notes, and snippets.

@Bound3R
Created June 24, 2023 14:01
Show Gist options
  • Save Bound3R/4421d1ee48d88936b24e1038684a8815 to your computer and use it in GitHub Desktop.
Save Bound3R/4421d1ee48d88936b24e1038684a8815 to your computer and use it in GitHub Desktop.
session 24/6
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