I just want it to be as simple as possible so I excluded all the errors and all that were mentioned in the React docs as I know that we will be taught all about APIs later on in the upcoming certifications.
Code pen Link(please only see the JS part)
Code:
My code here
class MyComponent2 extends React.Component {
constructor(props) {
super(props);
this.state = {
quote: "",
author: ""
};
}
componentDidMount() {
fetch("https://api.quotable.io/random")
.then((response) => response.json())
.then((data) => {
console.log(data.content);
this.setState({
quote: data.content,
author: data.author
});
});
}
render() {
return <div> Hello World {this.state.quote} {this.state.author} </div>;
}
}
ReactDOM.render(<MyComponent2 />, document.getElementById("root"));