React Hooks
vuer-rtc provides React hooks for seamless integration with React applications.
See Operations for the complete reference of operation types you can use with these hooks.
Installation
The hooks are available from the /hooks subpath:
GraphProvider
Wrap your app with GraphProvider to provide the graph context:
Props
| Prop | Type | Description |
|---|---|---|
sessionId | string | Unique session identifier |
onSend | (msg: CRDTMessage) => void | Callback when a message is ready to send |
useGraph
Get the current graph state:
useNode
Subscribe to a specific node by key. Re-renders only when that node changes:
useNodeProperty
Subscribe to a specific property of a node. More granular than useNode—only re-renders when that property changes:
useRootKey
Subscribe to the root node key. Re-renders only when the root key changes:
useGraphActions
Get actions to modify the graph:
Available Actions
| Action | Signature | Description |
|---|---|---|
edit | (op: Operation) => void | Add operation to edit buffer (uncommitted) |
commit | (description?: string) => void | Commit edits as a single message |
cancelEdits | () => void | Discard uncommitted edits |
undo | () => void | Undo last committed message |
redo | () => void | Redo last undone message |
receive | (msg: CRDTMessage) => void | Process incoming remote message |
useUndoRedoShortcuts
Enables keyboard shortcuts for undo/redo:
- Cmd/Ctrl+Z: Undo
- Cmd/Ctrl+Shift+Z: Redo
Full Example
Next: See the Complete Integration Guide for end-to-end examples of building collaborative applications.