Skip to content

Commit d24a709

Browse files
committed
refactor: 복잡한 return 수정
1 parent d268a8e commit d24a709

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

frontend/src/components/CursorView.tsx

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Panel } from "@xyflow/react";
22
import { useReactFlow } from "@xyflow/react";
33
import { type AwarenessState } from "@/hooks/useCursor";
44
import Cursor from "./cursor";
5+
import { useMemo } from "react";
56

67
interface CollaborativeCursorsProps {
78
cursors: Map<number, AwarenessState>;
@@ -10,20 +11,23 @@ interface CollaborativeCursorsProps {
1011
export function CollaborativeCursors({ cursors }: CollaborativeCursorsProps) {
1112
const { flowToScreenPosition } = useReactFlow();
1213

13-
return (
14-
<Panel position="top-left" className="pointer-events-none">
15-
{Array.from(cursors.values()).map((cursor) => {
16-
if (!cursor.cursor) return null;
17-
18-
const position = flowToScreenPosition({
19-
x: cursor.cursor.x,
20-
y: cursor.cursor.y,
21-
});
14+
const validCursors = useMemo(
15+
() => Array.from(cursors.values()).filter((cursor) => cursor.cursor),
16+
[cursors],
17+
);
2218

23-
return (
24-
<Cursor key={cursor.clientId} coors={position} color={cursor.color} />
25-
);
26-
})}
19+
return (
20+
<Panel>
21+
{validCursors.map((cursor) => (
22+
<Cursor
23+
key={cursor.clientId}
24+
coors={flowToScreenPosition({
25+
x: cursor.cursor!.x,
26+
y: cursor.cursor!.y,
27+
})}
28+
color={cursor.color}
29+
/>
30+
))}
2731
</Panel>
2832
);
2933
}

0 commit comments

Comments
 (0)