Advertisement
ernannicf

List.js

Oct 20th, 2019
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { Component } from 'react'
  2. import { View, Text } from 'react-native'
  3. import axios from 'axios'
  4.  
  5. class List extends Component {
  6.  
  7.   state = {
  8.     username: this.props.navigation.getParam('name'),
  9.     reposList: []
  10.   }
  11.   constructor(props){
  12.     super(props)
  13.   }
  14.   componentDidMount() {
  15.     axios.get(`https://api.github.com/users/${this.state.username}/repos`)
  16.       .then(response => {
  17.         alert(response)
  18.         this.setState({reposList: response})
  19.       })
  20.       .catch(error => alert(error))
  21.   }
  22.  
  23.   mountList() {
  24.     return this.state.reposList.map(item, index => {
  25.       return (
  26.         <View>
  27.           <Text>{item.name}</Text>
  28.           <Text>{item.full_name}</Text>
  29.         </View>
  30.       )
  31.     })
  32.   }
  33.  
  34.   render() {
  35.     return (
  36.       <View>
  37.         <Text>{this.state.reposList}</Text>
  38.       </View>
  39.     )
  40.   }
  41. }
  42.  
  43. List.navigationOptions = {
  44.   title: 'List'
  45. }
  46.  
  47. export default List
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement