Skip to main content

Overview

useIsSynchronized returns true when your local React Together state is fully synchronized with the shared model, and false when synchronization is in progress or when not connected to a session. This hook is crucial for showing loading states and ensuring users know when their changes are fully propagated.
Perfect for: Loading indicators, sync status displays, preventing actions during sync, optimistic UI patterns, and debugging synchronization issues.

Basic Usage

Signature

Return Value

boolean
true if connected to a session and all state is synchronized with the model, false during sync or when disconnected

How It Works

The hook returns true when all of these conditions are met:
  1. Connected to session - User is in a React Together session
  2. Has participants - At least one user (including yourself) has state
  3. Model synchronized - The underlying Croquet model is caught up with events

Examples

Synchronization Loading Indicator

Show a loading state while state synchronization is in progress:

Advanced Connection Dashboard

Build a comprehensive status dashboard:

Optimistic UI with Sync Feedback

Show immediate feedback while ensuring sync status is clear:

Form Submission with Sync Validation

Prevent form submission until changes are synchronized:

Real-time Collaboration Editor

Show sync status in a collaborative text editor:

Best Practices

Debounced Sync Indicator

Avoid flickering sync indicators with proper debouncing:

Sync State Management

Track sync state changes for analytics:

Common Patterns

  • Loading States: Show spinners or disabled states while not synchronized
  • Optimistic Updates: Update UI immediately, show pending state until synced
  • Form Validation: Prevent submission until changes are synchronized
  • Auto-save Indicators: Show when documents are being saved/synced
  • Conflict Resolution: Handle cases where sync takes longer than expected

TypeScript Support

useIsSynchronized is fully typed and returns a boolean value:

Technical Notes

The hook checks three conditions: session connection, presence of at least one user with state, and model synchronization with the Croquet reflector. Heavy model processing can temporarily cause false returns.
Synchronization status can change rapidly during heavy usage. Use debouncing techniques to avoid UI flickering and provide smooth user experiences.