Skip to main content
Complete Steps 1-2 on the Core setup page before continuing. Those steps install dependencies and initialize Velt.

Setup

Step 1: Create a CRDT map store

Use the useStore hook with type: 'map' to create a CRDT store backed by a Yjs Y.Map. The hook handles store initialization, React lifecycle, and real-time subscriptions automatically — no manual useState/useEffect needed for store setup.

Step 2: Read the store

Read the current map value at any time. The CRDT library keeps the value automatically synced with all collaborators.
The hook’s value field reactively tracks the current map — re-renders automatically on every local and remote change, so no manual subscription is needed. You can also read the latest synchronous value at any time via store.getValue() (useful inside event handlers).

Step 3: Update the store

Use update() to replace the entire map value. The CRDT library handles conflict-free merging with other users’ edits automatically.

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)

By default, initialValue is only applied when the document has no existing remote state. Set forceResetInitialContent to true to always reset the store to initialValue on initialization, overwriting any existing remote data.

Complete Example

A complete collaborative key-value editor built with useStore:
Complete Implementation