handle undefined values, clarify comment

This commit is contained in:
Tom (plebeius.eth)
2024-06-15 12:37:45 +02:00
parent efc9a98f47
commit cadddcb4c5
4 changed files with 11 additions and 9 deletions
+4 -4
View File
@@ -4,17 +4,17 @@ import { flattenCommentsPages } from '@plebbit/plebbit-react-hooks/dist/lib/util
const useReplies = (comment: Comment) => {
// flatten all replies including nested ones from the original comment
const flattenedReplies = useMemo(() => flattenCommentsPages(comment.replies), [comment.replies]);
const flattenedReplies = useMemo(() => flattenCommentsPages(comment?.replies), [comment?.replies]);
// generate a Set of CIDs from flattened replies for quick lookup
const replyCids = useMemo(() => new Set(flattenedReplies.map((reply) => reply.cid)), [flattenedReplies]);
const replyCids = useMemo(() => new Set(flattenedReplies.map((reply) => reply?.cid)), [flattenedReplies]);
// filter against the original comment's CID and all CIDs in flattened replies
const filter = useCallback(
(accountComment: Comment) => {
return accountComment.parentCid === comment.cid || replyCids.has(accountComment.parentCid);
return accountComment.parentCid === comment?.cid || replyCids.has(accountComment.parentCid);
},
[comment.cid, replyCids],
[comment?.cid, replyCids],
);
const { accountComments } = useAccountComments({ filter });