diff --git a/src/components/Post.js b/src/components/Post.js index f01dfd4..634a330 100644 --- a/src/components/Post.js +++ b/src/components/Post.js @@ -32,10 +32,10 @@ const Post = ({ post, recursionDepth, selectPost, reload }) => { postApi.reactToPost(post.id, null).then(reload); } - const getComments = (post) => { + const getComments = (post, recursionDepth) => { let nrOfComments = post.comments.length; - post.comments.forEach(comment => { - nrOfComments += getComments(comment); + if (recursionDepth !== 0) post.comments.forEach(comment => { + nrOfComments += getComments(comment, recursionDepth - 1); }) return nrOfComments; } @@ -53,7 +53,7 @@ const Post = ({ post, recursionDepth, selectPost, reload }) => { {recursionDepth !== 0 &&
- {getComments(post)} + {getComments(post, recursionDepth-1)}
}