Skip to content

Commit 82a6c5a

Browse files
committed
perf: remove state in favor of using a ref
1 parent 60691b0 commit 82a6c5a

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

package/src/components/Message/Message.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -326,9 +326,7 @@ const MessageWithContext = (props: MessagePropsWithContext) => {
326326
const isMessageTypeDeleted = message.type === 'deleted';
327327
const { client } = chatContext;
328328

329-
const [rect, setRect] = useState<{ w: number; h: number; x: number; y: number } | undefined>(
330-
undefined,
331-
);
329+
const rectRef = useRef<Rect>(undefined);
332330
const bubbleRect = useRef<Rect>(undefined);
333331
const contextMenuAnchorRef = useRef<View>(null);
334332

@@ -338,8 +336,8 @@ const MessageWithContext = (props: MessagePropsWithContext) => {
338336
const layout = await measureInWindow(messageWrapperRef, insets);
339337
const bubbleLayout = await measureInWindow(contextMenuAnchorRef, insets).catch(() => layout);
340338

339+
rectRef.current = layout;
341340
bubbleRect.current = bubbleLayout;
342-
setRect(layout);
343341
setOverlayMessageH(layout);
344342
openOverlay({ id: messageOverlayId, messageId: message.id });
345343
} catch (e) {
@@ -814,6 +812,7 @@ const MessageWithContext = (props: MessagePropsWithContext) => {
814812
const styles = useStyles({
815813
highlightedMessage: (isTargetedMessage || message.pinned) && !isMessageTypeDeleted,
816814
});
815+
const rect = rectRef.current;
817816
const overlayItemsAnchorRect = bubbleRect.current ?? rect;
818817

819818
if (!(isMessageTypeDeleted || messageContentOrder.length)) {

0 commit comments

Comments
 (0)