
Setup
Step 1: Add Comment components
- Add the
Velt Commentscomponent to the root of your app. - This component is required to render comments in your app.
- Set the
text modeprop tofalseto hide the default text comment tool.
- React / Next.js
Step 2: Install the Velt DraftJS extension
Step 3: Configure the DraftJS editor with the Velt Comments extension
UseDraftJSVeltEditor instead of the standard DraftJS Editor. This wrapper component handles the DraftJS decorator setup, content change detection, and annotation tracking.
- React / Next.js
Step 4: Add a comment button to your DraftJS editor
- Add a button that users can click after selecting text in the DraftJS editor.
- Use
onMouseDownwithpreventDefault()so the browser does not move focus away from the editor and clear the current text selection.
- React / Next.js
Step 5: Call addComment to add a comment
- Call this method to add a comment to selected text in the DraftJS editor.
- Params:
AddCommentRequesteditor: DraftJS editor wrapper object with{ editorState, setEditorState }.editorId: Id of the editor. Use this if you have multiple DraftJS editors on the same page. (optional)context: Add custom metadata to the Comment Annotation. Learn more. (optional)
- React / Next.js
Step 6: Render comments in DraftJS editor
- Get comment data from Velt SDK and render it in the DraftJS editor.
- Params:
RenderCommentsRequesteditor: DraftJS editor wrapper object with{ editorState, setEditorState }.editorId: Id of the editor. Use this if you have multiple DraftJS editors on the same page. (optional)commentAnnotations: Array of Comment Annotation objects.
- React / Next.js
Step 7: Persist DraftJS content without Velt comment entities (optional)
- When saving editor content to your backend, remove Velt comment entities to keep your stored content clean.
- Use
exportContentStateWithoutCommentsbefore converting DraftJS content to raw JSON.
Step 8: Style the commented text
- Style the commented text by adding CSS for the
velt-comment-textelement.
Complete Example
APIs
DraftJSVeltEditor
A wrapper around the DraftJSEditor component that automatically handles decorator setup, content change detection, and Velt annotation context updates.
- Props:
DraftJSVeltEditorPropseditorState: Current DraftJS editor state.onChange: Callback when the editor state changes.editorId: Optional editor ID for multi-editor scenarios.- All other standard DraftJS
Editorprops are forwarded.
- React / Next.js
addComment()
Creates a comment annotation for the currently selected text in the editor.- Signature:
async (request:AddCommentRequest) => Promise<void> - Params:
request:AddCommentRequest - Returns:
Promise<void>
- React / Next.js
renderComments()
Renders and highlights comment annotations in the DraftJS editor.- Signature:
(request:RenderCommentsRequest) => void - Params:
request:RenderCommentsRequest - Returns:
void
- React / Next.js
exportContentStateWithoutComments()
Returns a DraftJSContentState without Velt comment entities. Use it before saving content outside Velt.
- React / Next.js

