Skip to content

Instantly share code, notes, and snippets.

@aravi365
Last active February 5, 2022 06:40
Show Gist options
  • Save aravi365/236cde5dcd693ccd93a797d0e8ef32e4 to your computer and use it in GitHub Desktop.
Save aravi365/236cde5dcd693ccd93a797d0e8ef32e4 to your computer and use it in GitHub Desktop.
import React from 'react';
import {Text, View, FlatList} from 'react-native';
import {withLoaderList} from './withLoaderList';
const ListWithLoader = withLoaderList(FlatList);
export default function ListScreen() {
//states for loading and list data
const [listData, setListData] = React.useState([]);
const [loading, setLoading] = React.useState(false);
//fetch data from API
React.useEffect(() => {
const getListData = async () => {
setLoading(true);
//get api data and store it in listData
setLoading(false);
};
getListData();
}, []);
const renderItem = ({item, index}) => {
return (
<View style={styles.listContainer}>
<Text style={styles.listText}>{item.title}</Text>
</View>
);
};
return (
<View style={styles.container}>
<ListWithLoader
isLoading={loading}
style={styles.fList}
data={listData}
renderItem={renderItem}
/>
</View>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment