Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

Commit

Permalink
fix: optimistic update list (#2387)
Browse files Browse the repository at this point in the history
  • Loading branch information
alantoa authored Aug 21, 2023
1 parent 80a63a0 commit e3240b6
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions packages/app/hooks/api/use-comments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,25 @@ export const useComments = (nftId?: number) => {
[]);
const deleteComment = useCallback(
async function deleteComment(commentId: number) {
mutateComments(
(d) => {
if (d) {
d.forEach(
(_, index) =>
(d[index].comments = d[index]?.comments.filter(
(comment) => comment.id !== commentId
))
);
return [...d];
}
},
{ revalidate: false }
);
await axios({
url: `/v1/deletecomment/${commentId}`,
method: "POST",
data: {},
});

mutateComments();
},
[mutateComments]
);
Expand Down

0 comments on commit e3240b6

Please sign in to comment.