Skip to main content

Overview

useCursors enables real-time cursor tracking and display in collaborative applications. It automatically captures mouse movements and broadcasts cursor positions to all connected users, making it perfect for collaborative editing, design tools, presentations, and any application where user awareness is important.
Perfect for: Collaborative editors, design tools, presentation software, drawing applications, code editors, interactive dashboards, and any feature requiring real-time user cursor awareness.

Basic Usage

Signature

Parameters

UseCursorsOptions
default:"{}"
Optional configuration object for cursor behavior

UseCursorsOptions

boolean
default:"false"
Whether to remove the cursor when the user’s mouse leaves the window
boolean
default:"true"
Whether to exclude the current user’s cursor from allCursors
number
default:"50"
Delay in milliseconds between cursor position updates (50ms = 20 updates per second)

Return Value

Cursor | null
The current user’s cursor position, or null if not tracking
Record<string, Cursor>
Object mapping user IDs to their cursor positions

Cursor Interface

number
X-coordinate relative to the viewport (window)
number
Y-coordinate relative to the viewport (window)
number
X-coordinate relative to the document (including scroll)
number
Y-coordinate relative to the document (including scroll)
number
X-coordinate as percentage of document width (0-100)
number
Y-coordinate as percentage of document height (0-100)

Examples

Collaborative Design Tool

Code Editor with Cursor Tracking

Presentation Mode with Pointer

Gaming/Interactive Experience

Best Practices

Performance Optimization

Cursor Visualization

Coordinate Systems

TypeScript Support

The hook provides full TypeScript support with detailed interfaces: