Skip to main content
The useCreateRandomSession hook returns a function that, when called, connects the user to a new React Together session with a randomly generated name and password. This is perfect for quickly starting new collaborative sessions without having to manually specify session details.

Basic Usage

Signature

Return Value

() => void
A function that, when called, connects the user to a new React Together session with randomly generated credentials.

Examples

Quick Session Launcher

Create a simple interface for starting new sessions:

Meeting Room Creator

Create a more sophisticated meeting room interface:

Game Lobby Creator

Create game sessions with random room codes:

Study Group Launcher

Create instant study sessions:

Best Practices

Session Management

  • Clear user feedback - Always show loading states when creating sessions
  • Error handling - Gracefully handle session creation failures
  • Session persistence - Consider storing session context for user experience

User Experience

  • Immediate feedback - Show session status changes instantly
  • Share functionality - Make it easy to invite others to the session
  • Visual indicators - Use clear visual cues for session states

Integration Patterns

  • Combine with other hooks - Use with useIsTogether, useJoinUrl, and useConnectedUsers
  • State management - Track session metadata in local storage or state
  • Responsive design - Ensure session creators work on all device sizes

Common Use Cases

Quick Collaboration

Perfect for impromptu collaboration sessions:

Game Lobbies

Create instant game rooms:

Study Groups

Start educational sessions:

TypeScript Support

This hook has a simple, type-safe signature:
The session credentials (name and password) are automatically generated and handled internally. Users don’t need to manage these details when using random sessions.