Created
May 12, 2019 12:20
-
-
Save nikola-bodrozic/58ad2393983141766aef459b42c21911 to your computer and use it in GitHub Desktop.
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 axios from "axios"; | |
| class Comments extends Component { | |
| constructor(props) { | |
| super(props); | |
| this.state = { | |
| postId: '', | |
| commentBody:'' | |
| }; | |
| } | |
| componentDidMount() { | |
| this.getComments(); | |
| } | |
| getComments = async () => { | |
| const res = await axios.get("http://localhost:3005/posts/1"); | |
| const data = await res.data; | |
| const id = data.id | |
| this.setState({ postId: data.id }); | |
| const res2 = await axios.get("http://localhost:3005/comments/"+id); | |
| const data2 = await res2.data; | |
| this.setState({ commentBody: data2.body }); | |
| }; | |
| render() { | |
| return <p>post id <strong>{this.state.postId}</strong> and its comment <strong>{this.state.commentBody}</strong></p>; | |
| } | |
| } | |
| export default Comments; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment