From b608c5eae610b1523c75bbe71e96b609aa6a8fb1 Mon Sep 17 00:00:00 2001 From: Alf Eaton Date: Thu, 7 Mar 2024 10:41:46 +0000 Subject: [PATCH] Wrap onCommentEdited in useCallback (#17379) GitOrigin-RevId: 3171ed2a50502d0771457a3f3547eacec33efa20 --- .../hooks/use-review-panel-state.ts | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/services/web/frontend/js/features/ide-react/context/review-panel/hooks/use-review-panel-state.ts b/services/web/frontend/js/features/ide-react/context/review-panel/hooks/use-review-panel-state.ts index 0ae9be2a2a..6059b852fe 100644 --- a/services/web/frontend/js/features/ide-react/context/review-panel/hooks/use-review-panel-state.ts +++ b/services/web/frontend/js/features/ide-react/context/review-panel/hooks/use-review-panel-state.ts @@ -956,19 +956,18 @@ function useReviewPanelState(): ReviewPanelStateReactIde { [onThreadDeleted, projectId] ) - const onCommentEdited: ReviewPanel.UpdaterFn<'saveEdit'> = ( - threadId: ThreadId, - commentId: CommentId, - content: string - ) => { - setCommentThreads(prevState => { - const thread = { ...getThread(threadId) } - thread.messages = thread.messages.map(message => { - return message.id === commentId ? { ...message, content } : message + const onCommentEdited = useCallback( + (threadId: ThreadId, commentId: CommentId, content: string) => { + setCommentThreads(prevState => { + const thread = { ...getThread(threadId) } + thread.messages = thread.messages.map(message => { + return message.id === commentId ? { ...message, content } : message + }) + return { ...prevState, [threadId]: thread } }) - return { ...prevState, [threadId]: thread } - }) - } + }, + [getThread] + ) const saveEdit = useCallback( (threadId: ThreadId, commentId: CommentId, content: string) => {