Skip to main content
Complete Steps 1-2 on the Core setup page before continuing. Those steps install dependencies and initialize Velt.
The XML store requires direct Yjs manipulation, so you also need the yjs package:

Setup

Step 1: Create a CRDT XML store

Use the useStore hook with type: 'xml' to create a CRDT store backed by a Yjs Y.XmlFragment. Unlike text/map/array stores, the XML store does not use the hook’s update() method. All mutations must go through Yjs APIs directly via store.getXml().

Step 2: Manipulate the XML tree with Yjs APIs

Use Y.XmlElement and Y.XmlFragment APIs to read and modify the tree. Fine-grained Yjs operations (setAttribute, insert, delete) give better CRDT merge behavior than whole-document replacement.

Step 3: Subscribe to real-time changes

For XML stores, use store.subscribe() to listen for changes from all collaborators. Re-read the Y.XmlFragment in the callback to rebuild your in-memory data structure.

Step 4: Save and restore versions (optional)

Create checkpoints and roll back when needed.
The useStore hook exposes version management methods directly:

Step 5: Initial content with forceResetInitialContent (optional)

For XML stores, initial content is applied manually by checking if the Y.XmlFragment is empty. To force-reset, clear the fragment and re-populate inside a Yjs transaction.

Complete Example

A complete collaborative outline editor built with useStore and direct Yjs manipulation:OutlineNode type and Yjs helpers
Yjs Helpers
OutlineEditor component
Complete Implementation