Last active
February 5, 2022 06:40
-
-
Save aravi365/236cde5dcd693ccd93a797d0e8ef32e4 to your computer and use it in GitHub Desktop.
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 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