Hook Categories
Lifecycle
Initialization and teardown
Content
Document changes
Selection
Cursor and selection
Features
Comments, track changes, etc.
Lifecycle Hooks
onBeforeCreate
Called before the editor view is created.
Editor instance (partially initialized)
onCreate
Called when editor is fully initialized and ready.
Fully initialized editor instance
onDestroy
Called when editor is being destroyed.
No parameters passed. Clean up resources here.
onFirstRender
Called after the first render completes.
Content Hooks
onUpdate
Called when document content changes.
Editor instance
ProseMirror transaction
onTransaction
Fires for every transaction including selection changes. Use sparingly.
Editor instance
ProseMirror transaction
Transaction processing time in milliseconds
onContentError
Called when content processing fails.
Error object with details
Editor instance
Document identifier
Original file that failed
Selection Hooks
onSelectionUpdate
Called when selection changes (cursor movement).
Editor instance
ProseMirror transaction
onFocus
Called when editor gains focus.
Editor instance
Browser focus event
onBlur
Called when editor loses focus.
Editor instance
Browser blur event
Feature Hooks
Comments Hooks
onCommentsUpdate
Editor instance with updated comments
onCommentsLoaded
Editor instance
Loaded comments array
Whether file was replaced
Track Changes Hooks
onTrackedChangesUpdate
Editor instance with track changes
Collaboration Hooks
onCollaborationReady
Editor instance
Yjs document instance
Common Patterns
Auto-save with Debouncing
Error Recovery
Performance Tips
Best practices for hooks:
- Debounce expensive operations
- Use
onTransaction
sparingly - Check
transaction.docChanged
before processing - Clean up resources in
onDestroy
- Batch initialization in
onCreate