Skip to main content

Overview

useMyId returns the unique identifier of the current user when connected to a React Together session. This ID is persistent throughout the session and is essential for implementing user-specific features, personal data management, and identifying the current user in collaborative contexts.
Perfect for: User avatars, personal settings, per-user data, user identification, access control, and distinguishing “self” from other users.

Basic Usage

Signature

Return Value

string | null
The unique identifier of the current user, or null if not connected to a session

Examples

User Avatar with Self-Identification

Create a user list that highlights the current user:

Personal Settings Management

Store and manage per-user settings:

User-Specific Workspace

Create personalized workspaces for each user:

Chat System with User Identification

Build a chat system that identifies the current user:

Access Control and Permissions

Implement user-based access control:

User Progress Tracking

Track individual user progress in a collaborative app:

Best Practices

Safe ID Usage

Always check for null before using the ID:

ID-Based State Management

Use the ID for user-specific state keys:

Common Patterns

  • User Identification: Distinguish the current user from others
  • Personal Data: Store user-specific information and settings
  • Access Control: Implement user-based permissions and roles
  • Progress Tracking: Track individual user progress and achievements
  • UI Personalization: Customize interface based on user identity

TypeScript Support

useMyId is fully typed and returns a string or null:

Technical Notes

useMyId is an alias for useViewId from @multisynq/react. The ID is stable throughout a session but may change between different sessions.
Always check for null before using the ID. The hook returns null when not connected to a session, which can cause runtime errors if not handled properly.