InitialData
TheinitialData prop allows you to populate the Excalidraw canvas with elements, app state, and files when the component mounts.
Type Definition
initialData prop accepts:
- A static object with initial data
- A Promise that resolves to initial data
- A function returning a Promise (useful for lazy loading)
null(starts with empty canvas)
Properties
readonly ExcalidrawElement[] | null
Array of elements to render on the canvas.Each element must be a valid Excalidraw element with all required properties. Elements will be automatically restored and validated during initialization.
Partial<AppState> | null
Partial app state to initialize the editor with.You only need to provide the properties you want to override from the default state. Common properties include:
boolean
default:"false"
When
true, automatically scrolls and zooms the canvas to fit all elements in view after initialization.Useful when loading scenes with elements that may be positioned far from the origin.LibraryItems | Promise<LibraryItems>
Library items to preload into the element library.Can be a static array or a Promise that resolves to library items. This allows you to provide default templates or frequently used element groups.
BinaryFiles
Binary file data for images and other file-based elements.Maps file IDs to their binary data. Required if your elements include images.
Usage Examples
Static Initial Data
Provide initial data as a static object:Async Loading
Load initial data asynchronously from an API:Lazy Loading with Promise
Use a Promise directly for lazy initialization:Loading from Local Storage
Restore previous session from local storage:With Library Items
Preload library with templates:Important Notes
Element Restoration: Elements provided in
initialData are automatically restored and validated. Missing or invalid properties are filled with defaults.Async Loading: When using async loading (Promise or function), Excalidraw shows a loading state until the data resolves.
Type Imports
Related
- ExcalidrawProps - Complete props reference
- ImportedDataState - Data structure for importing scenes