1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-24 20:36:40 +07:00
vault-frontend/src/hooks/node/useGrouppedComments.ts
2025-01-24 17:51:59 +07:00

18 lines
422 B
TypeScript

import { useMemo } from 'react';
import { IComment } from '~/types';
import { groupCommentsByUser } from '~/utils/fn';
export const useGrouppedComments = (
comments: IComment[],
order: 'ASC' | 'DESC',
lastSeen?: string,
) =>
useMemo(
() =>
(order === 'DESC' ? [...comments].reverse() : comments).reduce(
groupCommentsByUser(lastSeen),
[],
),
[comments, lastSeen, order],
);