Excalidraw Component API
TheExcalidraw component is the main React component that renders the complete Excalidraw editor. This page provides a comprehensive API reference for all available props, callbacks, and imperative API methods.
Import
Props Reference
Core Props
Callback fired when elements, appState, or files change. This is the primary way to track changes to the scene.Parameters:
elements- Array of all elements in the scene (ordered by z-index)appState- Current application statefiles- Binary files (images) used in the scene
Called on every state increment, both durable (user actions) and ephemeral (temporary states like dragging).Use this for fine-grained change tracking or implementing custom undo/redo.
Initial scene data to load when the component mounts. Can be an object, function, or Promise.ExcalidrawInitialDataState structure:
Callback to receive the Excalidraw imperative API instance. Use this to programmatically control the editor.See Imperative API section below for available methods.
Custom components to render inside Excalidraw. Can include
MainMenu, WelcomeScreen, Footer, Sidebar, or any custom React components.Appearance Props
Sets the editor theme. When not provided, users can toggle between themes using the theme button.
When
true, renders the editor in view-only mode with no editing capabilities. Useful for displaying existing diagrams.When
true, hides the UI chrome (toolbars, menus) for a distraction-free experience. Users can still toggle this manually.When
true, shows a grid on the canvas. Elements can snap to grid when this is enabled.When
true, enables snapping to other objects on the canvas.Name of the document/scene. Used as the default filename when exporting.
Behavior Props
When
true, automatically focuses the canvas on mount, enabling immediate keyboard interaction.When
true, detects scrolling outside the canvas to prevent accidental page scrolls.When
true, keyboard shortcuts work globally instead of only when canvas is focused.Controls whether to render scrollbars on the canvas. By default, scrollbars are rendered.
Collaboration Props
Indicates whether the editor is in collaboration mode. This affects UI elements and behavior.
Callback fired when the user’s pointer position changes. Essential for implementing real-time collaboration.Payload:
pointer.x,pointer.y- Scene coordinates of the pointerpointer.tool- Current tool (“pointer” or “laser”)button- Mouse button statepointersMap- Map of all active pointers (for multi-touch)
Event Callbacks
Called when paste is triggered. Return ClipboardData structure:
true to prevent the default paste behavior.text- Plain text from clipboardelements- Excalidraw elements if pasting from another Excalidraw instancefiles- File objects if pasting images
Called when elements are duplicated via mouse-drag, keyboard, paste, or library insert. Return modified elements to override the default duplication behavior.Parameters:
nextElements- All elements including the duplicatesprevElements- Elements before duplication (excludes duplicated elements)
You should return all elements (including deleted ones) if making changes. Do not mutate elements directly.
Called on pointer down events.
Called on pointer up events.
Called when the canvas scroll position or zoom level changes.Parameters:
scrollX- Horizontal scroll positionscrollY- Vertical scroll positionzoom- Zoom object withvalueproperty
Called when the current user follows or unfollows a collaborator.OnUserFollowedPayload:
Library & File Management
Called when the library items change (add, remove, update).Use this to persist library items to your backend or local storage.
Custom function to generate IDs for uploaded files. If not provided, Excalidraw generates random IDs.Useful when you need deterministic file IDs or want to integrate with your storage system.
URL to return to after opening the public library. Used in the libraries.excalidraw.com integration.
Link Handling
Called when a link element is clicked. Use this to handle link clicks with custom logic.If provided, default link opening behavior is disabled.
Generate a custom link for selected element(s). This enables users to create shareable links to specific elements or groups.Parameters:
id- Element ID or group IDtype- Whether it’s a single element or a group
Embedding
Controls which URLs can be embedded as iframe elements.Options:
true- Allow all embedsfalse- Disable all embedsstring[]- Array of allowed domains (e.g.,["youtube.com", "twitter.com"])RegExporRegExp[]- Regex pattern(s) for allowed URLsfunction- Custom validation function
Custom renderer for embeddable elements. Override the default iframe rendering.
Custom UI Rendering
Render custom UI in the top-left corner of the editor (above the toolbar).
Render custom UI in the top-right corner of the editor.
Render custom content in the statistics panel (shown when elements are selected).
UI Configuration
Configure which UI elements are displayed and their behavior.
Minimum editor width in pixels before sidebars can be docked. Below this width, sidebars always render as overlays.
Control visibility of canvas action buttons in the menu.ExportOpts:
When
false, hides the image tool from the toolbar.Custom function to determine the editor’s form factor. This affects UI layout and behavior.If not provided, Excalidraw determines this automatically based on viewport size.
Advanced Props
Language code for internationalization. Supported languages include: en, es, fr, de, pt, ru, zh, ja, ko, ar, hi, it, nl, pl, tr, vi, and more.
When
false, disables AI features like text-to-diagram and mermaid-to-diagram.When
true, shows deprecated font options in the font family selector.Imperative API
The imperative API is provided via theexcalidrawAPI prop callback:
Scene Methods
Update elements and/or app state.
Clear the canvas and reset state.
Get current non-deleted elements.
Get all elements including deleted ones.
Get elements as a Map for efficient lookup.
Apply incremental updates to elements.
Mutate a single element.
State Methods
Get the current app state.
Get the scene name.
File Methods
Get binary files (images) used in the scene.
Add binary files to the scene.
Library Methods
Update library items programmatically.
UI Methods
Change the active tool programmatically.ToolType: “selection” | “lasso” | “rectangle” | “diamond” | “ellipse” | “arrow” | “line” | “freedraw” | “text” | “image” | “eraser” | “hand” | “frame” | “magicframe” | “embeddable” | “laser”
Set a custom cursor.
Reset to the default cursor.
Toggle a sidebar’s visibility.
Show a toast notification.
Utility Methods
Force re-render of the scene.
Scroll to view specific elements.
Get the editor interface details.EditorInterface:
Control frame rendering settings.
Use this in conjunction with
viewModeEnabled to disable frame rendering.Register a custom action.
Clear undo/redo history.
Unique ID of the Excalidraw instance.
Event Listeners
The API also provides methods to subscribe to events. All event listener methods return an unsubscribe function.Listen to changes. Returns unsubscribe function.
Listen to increments. Returns unsubscribe function.
Listen to pointer down events. Returns unsubscribe function.
Listen to pointer up events. Returns unsubscribe function.
Listen to scroll/zoom changes. Returns unsubscribe function.
Listen to user follow events. Returns unsubscribe function.
Complete Example
Type Definitions
For complete TypeScript type definitions, see the source:See Also
- UI Components API - API reference for UI components
- Excalidraw Component - Usage guide and examples
- Embedding Guide - Learn how to embed Excalidraw
- Customization Guide - Customize the editor appearance