import React, { Component } from "react";
export default class Planets extends Component {
state = {
hasErrors: false,
planets: {}
};
componentDidMount() {
fetch("https://jsonplaceholder.typicode.com/posts")
.then(res => res.json())
.then(res => this.setState({ planets: res }))
.catch(() => this.setState({ hasErrors: true }));
}
render() {
return <div>{JSON.stringify(this.state.planets)}</div>;
}
}
No comments:
Post a Comment