Advertisement
cabteix

Perniferous

Oct 22nd, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. import { FlatList, ActivityIndicator, Text, View } from 'react-native';
  2. import React, { Component } from 'react';
  3. import { AppRegistry, StyleSheet, Alert, Button, Image } from 'react-native';
  4.  
  5.  
  6. export default class FetchExample extends React.Component {
  7.  
  8. constructor(props){
  9. super(props);
  10. this.state ={ isLoading: true}
  11. }
  12.  
  13. componentDidMount(){
  14. return fetch('https://api.myjson.com/bins/uvbl4')
  15. .then((response) => response.json())
  16. .then((responseJson) => {
  17.  
  18. this.setState({
  19. isLoading: false,
  20. dataSource: responseJson.names,
  21. }, function(){
  22.  
  23. });
  24.  
  25. })
  26. .catch((error) =>{
  27. console.error(error);
  28. });
  29. }
  30.  
  31.  
  32.  
  33. render(){
  34.  
  35. if(this.state.isLoading){
  36. return(
  37. <View style={{flex: 1, padding: 20}}>
  38. <ActivityIndicator/>
  39. </View>
  40. )
  41. }
  42.  
  43. return(
  44. <View style={{flex: 1, paddingTop:20}}>
  45. <View>
  46. <Text>Deli Paris</Text>
  47. <Text> </Text>
  48. </View>
  49. <FlatList
  50. data={this.state.dataSource}
  51. renderItem={this.renderItem.bind(this)}
  52. keyExtractor={({id}, index) => id}
  53. />
  54. </View>
  55. );
  56. }
  57.  
  58. renderItem({ item }) {
  59. return (
  60. <View>
  61. <Image
  62. source={{uri: item.uri}}
  63. />
  64. <Text>
  65. {item.username}
  66. </Text>
  67. <Text>
  68. {item.name}
  69. </Text>
  70. </View>
  71.  
  72. );
  73. }
  74.  
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement