Skip to main content

Excalidraw Component API

The Excalidraw 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

function
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 state
  • files - Binary files (images) used in the scene
function
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.
object | function | Promise
Initial scene data to load when the component mounts. Can be an object, function, or Promise.
ExcalidrawInitialDataState structure:
function
Callback to receive the Excalidraw imperative API instance. Use this to programmatically control the editor.
See Imperative API section below for available methods.
React.ReactNode
Custom components to render inside Excalidraw. Can include MainMenu, WelcomeScreen, Footer, Sidebar, or any custom React components.

Appearance Props

'light' | 'dark'
Sets the editor theme. When not provided, users can toggle between themes using the theme button.
boolean
default:"false"
When true, renders the editor in view-only mode with no editing capabilities. Useful for displaying existing diagrams.
boolean
default:"false"
When true, hides the UI chrome (toolbars, menus) for a distraction-free experience. Users can still toggle this manually.
boolean
default:"false"
When true, shows a grid on the canvas. Elements can snap to grid when this is enabled.
boolean
When true, enables snapping to other objects on the canvas.
string
Name of the document/scene. Used as the default filename when exporting.

Behavior Props

boolean
default:"false"
When true, automatically focuses the canvas on mount, enabling immediate keyboard interaction.
boolean
default:"true"
When true, detects scrolling outside the canvas to prevent accidental page scrolls.
boolean
default:"false"
When true, keyboard shortcuts work globally instead of only when canvas is focused.
Use with caution as this may interfere with other keyboard interactions on the page.
boolean
Controls whether to render scrollbars on the canvas. By default, scrollbars are rendered.

Collaboration Props

boolean
default:"false"
Indicates whether the editor is in collaboration mode. This affects UI elements and behavior.
function
Callback fired when the user’s pointer position changes. Essential for implementing real-time collaboration.
Payload:
  • pointer.x, pointer.y - Scene coordinates of the pointer
  • pointer.tool - Current tool (“pointer” or “laser”)
  • button - Mouse button state
  • pointersMap - Map of all active pointers (for multi-touch)

Event Callbacks

function
Called when paste is triggered. Return true to prevent the default paste behavior.
ClipboardData structure:
  • text - Plain text from clipboard
  • elements - Excalidraw elements if pasting from another Excalidraw instance
  • files - File objects if pasting images
function
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 duplicates
  • prevElements - Elements before duplication (excludes duplicated elements)
You should return all elements (including deleted ones) if making changes. Do not mutate elements directly.
function
Called on pointer down events.
function
Called on pointer up events.
function
Called when the canvas scroll position or zoom level changes.
Parameters:
  • scrollX - Horizontal scroll position
  • scrollY - Vertical scroll position
  • zoom - Zoom object with value property
function
Called when the current user follows or unfollows a collaborator.
OnUserFollowedPayload:

Library & File Management

function
Called when the library items change (add, remove, update).
Use this to persist library items to your backend or local storage.
function
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.
string
URL to return to after opening the public library. Used in the libraries.excalidraw.com integration.
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 ID
  • type - Whether it’s a single element or a group

Embedding

boolean | string[] | RegExp | RegExp[] | function
Controls which URLs can be embedded as iframe elements.
Options:
  • true - Allow all embeds
  • false - Disable all embeds
  • string[] - Array of allowed domains (e.g., ["youtube.com", "twitter.com"])
  • RegExp or RegExp[] - Regex pattern(s) for allowed URLs
  • function - Custom validation function
Be cautious when allowing embeds as they can pose security risks.
function
Custom renderer for embeddable elements. Override the default iframe rendering.

Custom UI Rendering

function
Render custom UI in the top-left corner of the editor (above the toolbar).
function
Render custom UI in the top-right corner of the editor.
function
Render custom content in the statistics panel (shown when elements are selected).

UI Configuration

object
Configure which UI elements are displayed and their behavior.
number
Minimum editor width in pixels before sidebars can be docked. Below this width, sidebars always render as overlays.
object
Control visibility of canvas action buttons in the menu.
ExportOpts:
boolean
default:"true"
When false, hides the image tool from the toolbar.
function
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

string
default:"en"
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.
boolean
default:"true"
When false, disables AI features like text-to-diagram and mermaid-to-diagram.
boolean
When true, shows deprecated font options in the font family selector.

Imperative API

The imperative API is provided via the excalidrawAPI prop callback:

Scene Methods

function
Update elements and/or app state.
function
Clear the canvas and reset state.
function
Get current non-deleted elements.
function
Get all elements including deleted ones.
function
Get elements as a Map for efficient lookup.
function
Apply incremental updates to elements.
function
Mutate a single element.

State Methods

function
Get the current app state.
function
Get the scene name.

File Methods

function
Get binary files (images) used in the scene.
function
Add binary files to the scene.

Library Methods

function
Update library items programmatically.

UI Methods

function
Change the active tool programmatically.
ToolType: “selection” | “lasso” | “rectangle” | “diamond” | “ellipse” | “arrow” | “line” | “freedraw” | “text” | “image” | “eraser” | “hand” | “frame” | “magicframe” | “embeddable” | “laser”
function
Set a custom cursor.
function
Reset to the default cursor.
function
Toggle a sidebar’s visibility.
function
Show a toast notification.

Utility Methods

function
Force re-render of the scene.
function
Scroll to view specific elements.
function
Get the editor interface details.
EditorInterface:
function
Control frame rendering settings.
Use this in conjunction with viewModeEnabled to disable frame rendering.
function
Register a custom action.
function
Clear undo/redo history.
string
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.
function
Listen to changes. Returns unsubscribe function.
function
Listen to increments. Returns unsubscribe function.
function
Listen to pointer down events. Returns unsubscribe function.
function
Listen to pointer up events. Returns unsubscribe function.
function
Listen to scroll/zoom changes. Returns unsubscribe function.
function
Listen to user follow events. Returns unsubscribe function.

Complete Example

Type Definitions

For complete TypeScript type definitions, see the source:

See Also