Skip to content

Instantly share code, notes, and snippets.

@Senhordim
Created September 16, 2017 16:48
Show Gist options
  • Save Senhordim/c1f323b29aa38d4ca2905095737ede20 to your computer and use it in GitHub Desktop.
Save Senhordim/c1f323b29aa38d4ca2905095737ede20 to your computer and use it in GitHub Desktop.
get endpoint with axios
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