Skip to main content

Overview

useHoveringUsers identifies which users are currently hovering over a specific DOM element in your collaborative application. This hook is ideal for creating interactive feedback, hover highlights, and real-time user interaction awareness.
Perfect for: Interactive elements, hover effects, collaborative drawing tools, real-time feedback systems, and any feature where you need to show user interaction with specific elements.
If a user is hovering a component that is nested within other hoverable components, only the innermost component will indicate that it’s being hovered.

Basic Usage

Signature

Parameters

string
required
Unique identifier for this hovering state. Must be unique across your application.

Return Value

The hook returns a tuple with three elements:
MutableRefObject<HTMLElement | null>
A React ref that must be attached to the DOM element you want to track hovering for
string[]
Array containing all user IDs that are currently hovering over the element
boolean
Whether the current user is hovering over the element

Examples

Interactive Button with User Feedback

Collaborative Drawing Canvas

Hover Zones with Visual Feedback

Nested Hover Detection

Best Practices

Performance Considerations

  • Unique Keys: Always use unique rtKey values across your application to avoid conflicts
  • Cleanup: The hook automatically handles cleanup when components unmount
  • Ref Assignment: Make sure to assign the returned ref to a DOM element, not a React component

User Experience

  • Visual Feedback: Provide clear visual feedback when users are hovering
  • Accessibility: Consider keyboard navigation and screen reader compatibility
  • Performance: Be mindful of complex hover interactions that might impact performance

Common Patterns

TypeScript Support

The hook is fully typed and will provide proper TypeScript intellisense: