Files
5chan/src/hooks/use-count-links-in-replies.ts
T
plebeius e556a9e662 chore(deps): replace plebbit/plebbit-react-hooks with bitsocialhq/pkc-react-hooks
bitsocialhq/pkc-react-hooks is a fork of plebbit-react-hooks that we're maintaining temporarily as an attempt to modernize the original repository using AI tools, possibly merging changes back into plebbit-react-hooks, which should also be rebranded to pkc-react-hooks eventually, under the org pkcprotocol.
2026-02-28 15:02:56 +08:00

21 lines
653 B
TypeScript

import { useMemo } from 'react';
import { Comment } from '@bitsocialhq/pkc-react-hooks';
import { flattenCommentsPages } from '@bitsocialhq/pkc-react-hooks/dist/lib/utils';
const useCountLinksInReplies = (comment: Comment, firstXReplies?: number) => {
let linkCount = 0;
const flattenedReplies = useMemo(() => flattenCommentsPages(comment?.replies), [comment?.replies]);
const repliesToConsider = firstXReplies !== undefined ? flattenedReplies.slice(0, firstXReplies) : flattenedReplies;
for (let reply of repliesToConsider) {
if (reply.link) {
linkCount++;
}
}
return linkCount;
};
export default useCountLinksInReplies;