Skip to content

Commit

Permalink
navigate to post from list on click
Browse files Browse the repository at this point in the history
  • Loading branch information
JHurdle91 committed Aug 26, 2021
1 parent 6a016e4 commit 4a8dad0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/components/PostList.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ const PostList = () => {
return (
<div className="PostList">
{posts.map((post) => {
const { title, timestamp, text } = post;
const { title, timestamp, text, _id } = post;
return (
<div>
<PostListItem
key={uniqid()}
id={_id}
title={title}
timestamp={timestamp}
body={text}
Expand Down
9 changes: 7 additions & 2 deletions src/components/PostListItem.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
const PostListItem = (props) => {
const { title, timestamp, body, nComments } = props;
const { title, timestamp, body, nComments, id } = props;

const handleClick = () => {
window.location.href = `/posts/${id}`;
};

return (
<div className="PostListItem">
<div className="PostListItem" onClick={handleClick}>
<h2>{title}</h2>
<div>{timestamp}</div>
<p>{body}</p>
Expand Down

0 comments on commit 4a8dad0

Please sign in to comment.