Skip to content

Commit 94498df

Browse files
committed
refactor: 핸들러 함수가 모두 updateCursorPosition을 사용하게 수정
1 parent d24a709 commit 94498df

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

frontend/src/hooks/useCursor.ts

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,13 @@ export function useCollaborativeCursors({
7171
}, [ydoc, roomName]);
7272

7373
const updateCursorPosition = useCallback(
74-
(x: number, y: number) => {
74+
(x: number | null, y: number | null) => {
7575
if (!provider.current?.awareness) return;
7676

77-
const cursor = flowInstance?.screenToFlowPosition({
78-
x,
79-
y,
80-
});
77+
const cursor =
78+
x !== null && y !== null
79+
? flowInstance?.screenToFlowPosition({ x, y })
80+
: null;
8181

8282
provider.current.awareness.setLocalState({
8383
cursor,
@@ -103,14 +103,8 @@ export function useCollaborativeCursors({
103103
);
104104

105105
const handleMouseLeave = useCallback(() => {
106-
if (!provider.current?.awareness) return;
107-
108-
provider.current.awareness.setLocalState({
109-
cursor: null,
110-
color: userColor.current,
111-
clientId: provider.current.awareness.clientID,
112-
});
113-
}, []);
106+
updateCursorPosition(null, null);
107+
}, [updateCursorPosition]);
114108

115109
return {
116110
cursors,

0 commit comments

Comments
 (0)