Installation
Quick Start
Wrap your editor with thewithCollaboration extension to enable real-time collaboration:
Configuration
ThewithCollaboration function accepts a configuration object:
Connection Management
Control the connection lifecycle manually:Collaboration API
The collaboration extension adds acollaboration namespace to the editor:
Connection State
React Hooks
useCollaboration
Access the current collaboration state:useConnectionStatus
Monitor just the connection status:useRemoteCursors
Access remote cursor positions:Remote Cursors
Show live cursor positions of other users: TheRemoteCursors component automatically displays:
- Live cursor positions with user colors
- User names on hover
- Selection ranges for multi-block selections
Complete Example
Here’s a full collaborative editor implementation:Undo/Redo with Collaboration
When collaboration is enabled, the undo/redo functionality automatically uses Yjs’sUndoManager, which only undoes local changes:
Events
Listen to collaboration events:Server Setup
You’ll need a WebSocket server that supports Yjs. The package includes aWebSocketProvider compatible with standard Yjs servers.
Example server setup with y-websocket:
Advanced: Custom Y.Doc
Provide your own Yjs document for advanced use cases:Best Practices
Always clean up connections
Always clean up connections
Use
useEffect cleanup functions to disconnect when components unmount:Handle connection failures gracefully
Handle connection failures gracefully
Monitor the connection status and show appropriate UI:
Use unique user IDs
Use unique user IDs
Generate stable user IDs that persist across sessions:
Provide initial values
Provide initial values
Seed the document with initial content for new rooms:
Troubleshooting
Users not seeing changes: Ensure all clients are connected to the sameroomId.
Cursors not showing: Make sure <RemoteCursors /> is inside <YooptaEditor>.
Connection drops: Check WebSocket server is running and accessible.
Sync issues: Verify the isSynced flag before considering the document ready.