---
agent:
  instructions: "Use this search API to find relevant content across this site with keywords or natural-language queries, instead of crawling individual pages. Results are returned in Markdown."
  endpoint: "https://excalidraw.heycactus.ai/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://developers.cloudflare.com/ai-search/how-to/search-for-agents/"
lang: en
---

# Excalidraw React component

The Excalidraw React component is the editor published as the `@excalidraw/excalidraw` npm package, version 0.18.0, for developers who embed it in their own React apps. You set how it starts with props such as `initialData`, `langCode` and `viewModeEnabled`, read and change the drawing through `onChange` and the imperative API, and turn off interaction or the default UI with `interaction` and `ui`.

> Verified against the product on 2026-11-23

## Install the component

The Excalidraw editor is published as the `@excalidraw/excalidraw` npm package, version 0.18.0, and it works in React apps. Its React and React DOM peer versions are `^17.0.2`, `^18.2.0` or `^19.0.0`.

Render the editor with the component's props. Pass `interaction={{ enabled: { links: true } }}` to keep links clickable while the editor is otherwise non-interactive.

## Props that set up the editor

Each prop below is passed to the component. Unless a row says otherwise, the editor uses the value it has when the prop is not set.

| Prop | What it does | Source |
| --- | --- | --- |
| `initialData` | Sets the first scene. It takes a value or a function, and the value can be a promise. | |
| `initialState` | Sets the starting app state. | |
| `langCode` | Sets the language. It defaults to the default language's code. | |
| `theme` | Sets the theme. When it is not set, the editor shows a toggle for it. | |
| `viewModeEnabled` | Turns on view mode. | |
| `activeTool` | Forces the active tool, as a controlled value. The tool stays active until the prop is unset. | |
| `zenModeEnabled`, `gridModeEnabled` | Set zen mode and grid mode. | |
| `isCollaborating` | Tells the editor whether a collaboration session is running. It defaults to off. | |
| `ownerDocument` | Sets the document the editor mounts into. It defaults to the global `document`. | |
| `renderEnvironment` | Supplies the canvas and image factories the renderer uses. Keep the object stable between renders, because the caches are keyed by its identity. | |
| `detectScroll` | Turns on scroll detection. It defaults to on. | |
| `handleKeyboardGlobally` | Passes keyboard events to the editor from anywhere on the page. It defaults to off. | |
| `autoFocus` | Focuses the editor when it mounts. It defaults to off. | |
| `aiEnabled` | Turns the AI features on. They stay on unless this is set to `false`. | |
| `imageOptions` | Sets limits for inserted images. Missing values fall back to the defaults. | |
| `libraryReturnUrl` | Sets the address the library returns to. | |

## Read and change the drawing from code

Two props receive the drawing as it changes. `onChange` receives the elements, the app state and the files each time they change. The imperative API has an `onChange` method that takes a callback and returns a function that removes it.

The API is handed out through `onExcalidrawAPI`, which runs as soon as the API exists. The editor is not mounted at that point, and its state is not set yet. Its methods include `updateScene`, `getSceneElements`, `getAppState`, `getFiles`, `resetScene`, `setActiveTool` and the `selection` group.

Lifecycle props run in this order: `onMount` runs when the editor root mounts and gets the API and the container. `onInitialize` runs once the initial scene is loaded. `onUnmount` runs when the root unmounts.

## Export from code

`exportScene` makes a canvas, a PNG or JPEG blob, or an SVG element, depending on its `type`. For PNG, `embedScene` writes the scene into the file's metadata, so the file can be opened again in Excalidraw. JPEG takes a `quality` between 0 and 1, which defaults to 0.92. JPEG has no transparency, so `canvasBackgroundColor: false` is ignored for it and the default background is used.

The `onExport` prop runs before a JSON export is saved, and it can wait for async work. It is called only for JSON exports, and it gets an abort signal.

## Turn off interaction or the default UI

Set `interaction={false}` to make the editor non-interactive. It still draws the scene and reacts to changes made through the API, but a user cannot change it. Setting it implies view mode. Pass a config object instead to keep some interactions on.

Set `ui={false}` to hide the default UI, such as the toolbar, menus and sidebars. Host UI passed as children keeps rendering. Canvas content still renders, and the editor stays interactive unless `interaction` is off. Pass `ui={{ enabled: { zoom: true } }}` or `ui={{ disabled: { minimap: true } }}` to keep or remove single controls.

`UIOptions` sets which canvas actions and tools show. The image tool is on unless `UIOptions.tools.image` is set to `false`.

## Related pages

- [Export and save](https://excalidraw.heycactus.ai/tv5dsf-export-and-save) covers exporting a drawing from the web app.
- [Library](https://excalidraw.heycactus.ai/bgy4s7-library) covers library items, which `onLibraryChange` reports when they change.
