Skip to main content

Overview

Excalidraw is designed to be easily embedded in React applications. You can integrate the full editor, customize its appearance, control its behavior, and interact with it programmatically.

Basic Embedding

Installation

First, install Excalidraw in your React project:

Simple Integration

Embed Excalidraw with minimal configuration:
Excalidraw requires a defined height. Make sure its parent container has a height set, either through CSS or inline styles.

Component Props

Essential Props

From packages/excalidraw/index.tsx:23-59, the main props available:

API Reference

ExcalidrawAPI Methods

Once you have the API reference, you can control Excalidraw programmatically:

Event Handlers

Available Callbacks

Excalidraw provides various event handlers:
1

onChange

Called when elements, app state, or files change:
2

onPointerUpdate

Track pointer/cursor movements:
3

onPointerDown / onPointerUp

Handle pointer events:
4

onScrollChange

Monitor scroll position:
5

onLibraryChange

Track library modifications:

Customizing the UI

Rendering Custom Components

Add custom UI elements to Excalidraw:

Using Built-in Components

Excalidraw exports reusable components:
From packages/excalidraw/index.tsx:283-294, Excalidraw exports several built-in components like MainMenu, WelcomeScreen, Footer, and Sidebar that can be customized.

Collaboration Support

Enabling Collaboration

Prepare Excalidraw for real-time collaboration:

Advanced Integration

With Next.js

Embed in a Next.js application:

With State Management

Integrate with Redux or other state management:

Custom File Handling

Control file ID generation:
Control how links are opened:

Embeddable Elements

Validating Embeddables

Control which URLs can be embedded:

Complete Integration Example

Best Practices

1

Set container height

Always ensure Excalidraw’s parent has a defined height.
2

Handle API carefully

Check if excalidrawAPI is available before calling methods.
3

Debounce auto-save

Use debouncing for auto-save to avoid performance issues.
4

Use dynamic imports

For Next.js or SSR, use dynamic imports with ssr: false.
5

Validate user input

Always validate embeddable URLs and custom data.

Next Steps

Customization

Learn about advanced customization options

Export

Export drawings programmatically

Storage

Implement data persistence

i18n

Add multi-language support