mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-24 20:36:40 +07:00
17 lines
424 B
TypeScript
17 lines
424 B
TypeScript
import { IComment } from '~/redux/types';
|
|
import { useMemo } from 'react';
|
|
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]
|
|
);
|