Created
April 16, 2022 16:39
-
-
Save enzzoperez/5d1141e6c815537771c075c75c1eff0c 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
//IMPORTS | |
interface ILogos { | |
light: string; | |
dark: string; | |
} | |
export interface HomeResponse { | |
id: string; | |
name: string; | |
slug: string; | |
abbr: string; | |
logos: ILogos; | |
} | |
const endpoint = '/leagues'; | |
const Home: React.FC = () => { | |
const {response, error, isLoading} = useRemoteData<HomeResponse[]>({ | |
url: endpoint, | |
}); | |
const renderItem: ListRenderItem<HomeResponse> = ({item}) => ( | |
<Text>{item.name}</Text> | |
); | |
if (isLoading) { | |
return <ActivityIndicator />; | |
} | |
if (error) { | |
return <Text>An error was happened</Text>; | |
} | |
return ( | |
<View style={styles.root}> | |
<FlatList | |
keyExtractor={item => item.id} | |
data={response} | |
renderItem={renderItem} | |
/> | |
</View> | |
); | |
}; | |
const styles = StyleSheet.create({ | |
root: { | |
flex: 1, | |
}, | |
}); | |
export default Home; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment