Skip to main content

Overview

useNicknames provides functionality to manage user nicknames in a React Together session. It allows you to set the current user’s nickname and retrieve all users’ nicknames for display purposes. The initial nickname for a user is derived using the deriveNickname prop passed to the ReactTogether component.
Perfect for: User identification, personalized chat interfaces, user lists, collaborative editing with user attribution, and any feature that needs to display human-readable user names.

Basic Usage

Signature

Return Value

The hook returns a tuple with three elements:
string
The current user’s nickname
(nickname: string) => void
Function to update the current user’s nickname
Record<string, string>
Object mapping all user IDs to their nicknames (userId → nickname)

Examples

Simple Nickname Editor

User Directory with Nicknames

Chat Interface with Nicknames

Nickname-based User Mentions

Advanced Nickname Management

Setup with ReactTogether

To use nicknames effectively, configure the deriveNickname prop on your ReactTogether component:

Best Practices

Performance Considerations

  • Debounce Updates: For real-time nickname editors, consider debouncing nickname updates
  • Local State: Use local state for temporary input values before committing nickname changes
  • Validation: Always validate and sanitize nickname input

User Experience

  • Character Limits: Enforce reasonable character limits (typically 20-30 characters)
  • Uniqueness: Consider if you want to enforce unique nicknames in your application
  • Persistence: Nicknames persist for the duration of the session but reset when users rejoin

Common Patterns

TypeScript Support

The hook is fully typed and provides excellent TypeScript support: