Skip to content

Instantly share code, notes, and snippets.

@enzzoperez
Created April 16, 2022 16:39
Show Gist options
  • Save enzzoperez/5d1141e6c815537771c075c75c1eff0c to your computer and use it in GitHub Desktop.
Save enzzoperez/5d1141e6c815537771c075c75c1eff0c to your computer and use it in GitHub Desktop.
//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