This package contains the TLDraw editor as a React component named <TLDraw>
. You can use this package to embed the editor in any React application.
🎨 Want to build your own TLDraw-ish app instead? Try @tldraw/core.
💕 Love this library? Consider becoming a sponsor.
Use your package manager of choice to install @tldraw/tldraw
and its peer dependencies.
yarn add @tldraw/tldraw
# or
npm i @tldraw/tldraw
Import the TLDraw
React component and use it in your app.
import { TLDraw } from '@tldraw/tldraw'
function App() {
return <TLDraw />
}
You can use the id
to persist the state in a user’s browser storage.
import { TLDraw } from '@tldraw/tldraw'
function App() {
return <TLDraw id="myState" />
}
You can control the TLDraw
component through its props.
import { TLDraw, TLDrawDocument } from '@tldraw/tldraw'
function App() {
const myDocument: TLDrawDocument = {}
return <TLDraw document={document} />
}
You can also control the TLDraw
component imperatively through the TLDrawState
API.
import { TLDraw, TLDrawState } from '@tldraw/tldraw'
function App() {
const handleMount = React.useCallback((state: TLDrawState) => {
state.selectAll()
}, [])
return <TLDraw onMount={handleMount} />
}
Internally, the TLDraw
component’s user interface uses this API to make changes to the component’s state. See the TLDrawState
section of the documentation for more on this API.
You can respond to changes and user actions using the onChange
callback. For more specific changes, you can also use the onPatch
, onCommand
, or onPersist
callbacks. See the documentation for more.
import { TLDraw, TLDrawState } from '@tldraw/tldraw'
function App() {
const handleChange = React.useCallback((state: TLDrawState, reason: string) => {
// Do something with the change
}, [])
return <TLDraw onMount={handleMount} />
}
See the project’s documentation.
See the contributing guide.
See the development guide.
See the example
folder for examples of how to use the <TLDraw/>
component.
Need help? Please open an issue for support.
Want to connect with other devs? Visit the Discord channel.
This project is licensed under MIT.
If you’re using the library in a commercial product, please consider becoming a sponsor.