Axios and Component State
Last updated
Was this helpful?
Last updated
Was this helpful?
Was this helpful?
// import React is must as React.createElement will be called in convert
import React, { Component } from "react";
import { View, Text } from "react-native";
import axios from "axios";
class AlbumList extends Component {
state = { albums: [] }; // class level property
componentWillMount() {
axios.get("https://rallycoding.herokuapp.com/api/music_albums")
.then(response => this.setState({albums: response.data}));
}
// Use render Method to help to return JSX Object
render() {
console.log(this.state)
return (
<View>
<Text>Album List</Text>
</View>
);
}
}
export default AlbumList;