Setup
3. Initialize Document
A Document is the space where you want your users to collaborate. For a design tool it’s the canvas. For a video editor, it’s the editor. For a documentation tool, it’s the document etc. A document is like a virtual house. Users in the same virtual house can see and interact with each other.
It is critical that you do the following steps within a child component and not within the same root component where you placed the VeltProvider.
Realistically, these steps should be done inside your component that represents your document.
1
Import the useSetDocumentId hook
Import the useSetDocumentId
hook.
import { useSetDocumentId } from '@veltdev/react';
2
Set a document ID
When your document has initialized and is ready for collaboration, call the useSetDocumentId()
hook and pass a unique ID representing your document.
Users logged into the same document ID can see each other’s Presence
, Cursors
, Comments
etc.
The SDK will not work without this call.
You can use separate document IDs to represent separate documents.
useSetDocumentId('unique-document-id');
Was this page helpful?