Skip to content

Instantly share code, notes, and snippets.

@mdshadman
Created October 24, 2019 18:04
Show Gist options
  • Save mdshadman/9711d73d8757662e823e8e9047239ac5 to your computer and use it in GitHub Desktop.
Save mdshadman/9711d73d8757662e823e8e9047239ac5 to your computer and use it in GitHub Desktop.
import React, { Component } from 'react'
import { View, Text, Button, FlatList, ActivityIndicator } from 'react-native';
import styles from './ApiStyles';
const ApiView = (props) => {
const { goForFetch, goForAxios, fromFetch, fromAxios, axiosData, renderItem, FlatListItemSeparator, dataSource, loading } = props
return (
<View style={styles.parentContainer}>
<View style={{ margin: 18 }}>
<Button
title={'Click using Fetch'}
onPress={goForFetch}
color='green'
/>
</View>
<View style={{ margin: 18 }}>
<Button
title={'Click using axios'}
onPress={goForAxios}
color='green'
/>
</View>
{fromFetch ?
<FlatList
data={dataSource}
ItemSeparatorComponent={FlatListItemSeparator}
renderItem={item => renderItem(item)}
keyExtractor={item => item.id.toString()}
/> : <FlatList
data={axiosData}
ItemSeparatorComponent={FlatListItemSeparator}
renderItem={item => renderItem(item)}
keyExtractor={item => item.id.toString()}
/>
}
{loading &&
<View style={styles.loader}>
<ActivityIndicator size="large" color="#0c9" />
<Text>Fetching Data</Text>
</View>
}
</View>
)
}
export default ApiView;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment