Skip to content

Commit

Permalink
Add show article page
Browse files Browse the repository at this point in the history
  • Loading branch information
k-nasa committed Aug 14, 2019
1 parent f832346 commit 662f06c
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/pages/show_article.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React from "react";
import { useState, useEffect } from "react";
import { getArticle } from "../api";

const ShowArticle = props => {
const [article, setArticle] = useState({});
const [comments, setComments] = useState([]);

useEffect(() => {
const id = props.match.params.id;
getArticle(id).then(resp => {
setArticle(resp.Article);
setComments(resp.Comments);
});
}, []);

return (
<div>
<h2>{article.title}</h2>
<p>{article.body}</p>
<h2>コメント</h2>
<p>id: {article.user_id}</p>

{comments.map((comment, i) => {
return (
<div key={i}>
<p>{comment.body} </p>
<p>{comment.created_at}</p>
</div>
);
})}
</div>
);
};

export default ShowArticle;

0 comments on commit 662f06c

Please sign in to comment.