From d7daea4e0e924d1c20be768ccab85026b99449ee Mon Sep 17 00:00:00 2001 From: Yang Wong Date: Tue, 16 Jan 2024 12:07:09 +0100 Subject: [PATCH] Move sorting logic before setComments for clarity --- ui/src/components/Comment/index.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ui/src/components/Comment/index.tsx b/ui/src/components/Comment/index.tsx index 5443378d..b69cb1c8 100644 --- a/ui/src/components/Comment/index.tsx +++ b/ui/src/components/Comment/index.tsx @@ -92,15 +92,15 @@ const Comment = ({ objectId, mode, commentId }) => { if (!data) { return; } + if (data.count <= 3) { + data.list.sort((a, b) => a.created_at - b.created_at); + } if (pageIndex === 1 || pageIndex === 0) { setComments(data?.list); } else { setComments([...comments, ...data.list]); } const user: Types.PageUser[] = []; - if (data.count <= 3) { - data.list.sort((a, b) => a.created_at - b.created_at); - } data.list.forEach((item) => { user.push({ id: item.user_id,