Overview
TheuseYooptaEditor hook provides access to the main editor instance (YooEditor) from any component within the Yoopta context. This is the primary way to interact with the editor programmatically.
Usage
Signature
Returns
YooEditor - The editor instance with full API access
Editor API
The returnedYooEditor instance provides access to:
Block Operations
insertBlock- Insert a new blockupdateBlock- Update block propertiesdeleteBlock- Remove a blockduplicateBlock- Duplicate an existing blocktoggleBlock- Change block type while preserving contentmoveBlock- Move a block to a different positionfocusBlock- Focus a specific blockmergeBlock- Merge blocks togethersplitBlock- Split a block into twoincreaseBlockDepth- Increase nesting leveldecreaseBlockDepth- Decrease nesting levelgetBlock- Get block data by ID or path
Element Operations
insertElement- Insert element within a blockupdateElement- Update element propertiesdeleteElement- Remove an elementgetElement- Get element by pathgetElements- Get all elements in a blockgetElementEntry- Get element with its pathgetElementPath- Get path to an elementisElementEmpty- Check if element is empty
Content & State
children- Current editor content asYooptaContentValuegetEditorValue()- Get current editor contentsetEditorValue(value)- Set editor contentisEmpty()- Check if editor is emptyreadOnly- Read-only state
Parsers
getHTML(content)- Export to HTMLgetMarkdown(content)- Export to MarkdowngetPlainText(content)- Export to plain textgetEmail(content, options)- Export for email templates
Events
on(event, callback)- Listen to editor eventsonce(event, callback)- Listen to event onceoff(event, callback)- Remove event listeneremit(event, payload)- Emit custom event
History
undo()- Undo last changeredo()- Redo last undone changebatchOperations(fn)- Batch multiple operations
Focus
isFocused()- Check if editor is focusedfocus()- Focus the editorblur(options)- Blur the editor
Examples
Programmatically Insert Content
Export Content
Listen to Changes
Error Handling
The hook will throw an error if used outside the Yoopta context:<YooptaEditor> or a component that has access to the Yoopta context.
See Also
- useBlockData - Get specific block data
- useYooptaFocused - Check editor focus state
- useBlockSelected - Check if block is selected