Skip to content

Commit 4f8f1f5

Browse files
committed
Removed fetchComments
1 parent 0478e99 commit 4f8f1f5

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/components/Comments.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState, useEffect, useContext } from 'react'
1+
import React, { useState, useEffect, useContext, useCallback } from 'react'
22
import { Link } from '@reach/router'
33
import Button from './Button'
44

@@ -39,8 +39,6 @@ const Comments = (props) => {
3939

4040
const [comment, setComment] = useState('')
4141

42-
const [fetchComments, setFetchComments] = useState(false)
43-
4442
const [commentId, setCommentId] = useState()
4543

4644
const [commentReply, setCommentReply] = useState('')
@@ -55,13 +53,14 @@ const Comments = (props) => {
5553

5654
const [replyAttachments, setReplyAttachments] = useState([])
5755

56+
const fetchStoryComments = useCallback(async () => {
57+
const response = await userStory.getComments(storyId)
58+
setComments(response.data.data.userStory.user_story_comments)
59+
}, [storyId])
60+
5861
useEffect(() => {
59-
const fetchStoryComments = async () => {
60-
const response = await userStory.getComments(storyId)
61-
setComments(response.data.data.userStory.user_story_comments)
62-
}
6362
fetchStoryComments()
64-
}, [storyId, fetchComments])
63+
}, [fetchStoryComments])
6564

6665
useEffect(
6766
() => () => {
@@ -82,7 +81,8 @@ const Comments = (props) => {
8281
await userStory.postComment(formData)
8382
setComment('')
8483
setAttachments([])
85-
setFetchComments(!fetchComments)
84+
85+
fetchStoryComments()
8686
}
8787

8888
const addCommentReply = async (data) => {
@@ -97,8 +97,9 @@ const Comments = (props) => {
9797
await userStory.postCommentReply(formData)
9898
setCommentReply('')
9999
setReplyAttachments([])
100-
setFetchComments(!fetchComments)
101100
setRepliesToggled(null)
101+
102+
fetchStoryComments()
102103
}
103104

104105
return (

0 commit comments

Comments
 (0)