Created
September 16, 2017 16:48
-
-
Save Senhordim/c1f323b29aa38d4ca2905095737ede20 to your computer and use it in GitHub Desktop.
get endpoint with axios
This file contains hidden or 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
import React, { Component } from 'react'; | |
import { | |
ScrollView | |
} from 'react-native'; | |
import axios from 'axios'; | |
import Items from './Items'; | |
export default class ListItems extends Component { | |
constructor(props) { | |
super(props); | |
this.state = { listItems: [] }; | |
} | |
componentWillMount() { | |
axios.get('https://jsonplaceholder.typicode.com/photos') | |
.then(response => { | |
this.setState({ listItems: response.data }); | |
}) | |
.catch(() => { | |
console.log('erro ao executar esse request'); | |
}); | |
} | |
render() { | |
return ( | |
<ScrollView> | |
{this.state.listItems.map(item => <Items key={item.id} item={item} />)} | |
</ScrollView> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment