@tsdraw/react package uses several internal hooks to manage canvas state. These are not exported as public API, but understanding them helps when building custom integrations.
useTsdrawCanvasController
The primary hook that wires up the editor, canvas element, event listeners, and rendering loop. It returns:Persistence hooks
WhenpersistenceKey is set, the component internally manages:
- IndexedDB storage via
TsdrawLocalIndexedDb— saves document and session snapshots - Cross-tab sync via
BroadcastChannel— other tabs with the same key receive updates - Session ID via
getOrCreateSessionId— tracks the browser session for conflict resolution
Rendering loop
The canvas controller sets up arequestAnimationFrame loop that:
- Reads the current viewport and shapes from the editor
- Calls the renderer to draw the background and shapes
- Draws selection and tool overlays on top