Overview
useConnectedUsers returns an array of all users currently connected to your React Together session. This hook is essential for building user awareness features, showing who’s online, and creating personalized collaborative experiences.
Perfect for: User lists, presence indicators, online status displays, collaborative user management, and any feature that needs to show who’s connected.
Basic Usage
Signature
Return Value
ConnectedUser[]
Array of all users connected to the current session
ConnectedUser Object
string
Unique identifier for the user
string
Display name for the user (can be changed using useNicknames hook)
boolean
Whether this user object represents the current user
string
deprecated
Deprecated since v0.3.3. Use
nickname instead.Examples
Basic User List
User Avatars
User Management with Actions
Real-time User Activity
Collaborative User Stats
User Connection Status
Advanced Usage
User Filtering and Search
User Grouping
Best Practices
Handle Empty States
Always handle cases where no users are connected
Distinguish Current User
Make it clear which user is the current user
Use Stable Keys
Always use userId as the key for lists
Provide User Context
Show additional context about users when available
Common Patterns
User Counter
User Initials
TypeScript Support
Troubleshooting
User list is empty
User list is empty
- Verify the
ReactTogetherprovider is properly configured - Check that you’re connected to a session
- Ensure the session is active and other users have joined
User information is outdated
User information is outdated
- The hook automatically updates when users join/leave
- If issues persist, check for JavaScript errors
- Verify the session connection is stable
isYou flag not working
isYou flag not working
- Ensure you’re properly connected to the session
- Check that your user ID is being set correctly
- Verify the session initialization is complete
Nicknames not updating
Nicknames not updating
- Use the
useNicknameshook to manage nickname changes - Check that nickname updates are being published to the session
- Verify all users have the latest nickname data
Related Hooks
useNicknames
Manage and update user nicknames
useCursors
Track cursor positions of connected users
useChat
Enable chat between connected users
useStateTogether
Share state between connected users
useConnectedUsers is foundational for building user-aware collaborative features. It provides the essential user information needed for most multiplayer functionality.