Skip to Content
React

React

npm install @quickdrawjs/react

The package re-exports everything from @quickdrawjs/core, so one import gives you the component and the engine (Store, Editor, diff helpers).

Basic usage

import { Quickdraw } from '@quickdrawjs/react' import '@quickdrawjs/core/quickdraw.css' export default function Board() { return ( <div style={{ position: 'fixed', inset: 0 }}> <Quickdraw theme="light" grid="lines" /> </div> ) }

The component renders a div that fills its container. Give the container real dimensions.

Props

PropTypeDefault
theme'light' | 'dark''light'Live-switchable
grid'none' | 'lines' | 'dots''none'The backdrop; live-switchable
readonlybooleanfalseLock input (also hides the toolbar)
hideUibooleanfalseHide the stock toolbar — bring your own
themeTogglebooleantrueShow the theme switch in the board menu
gridControlbooleantrueShow the grid switch in the board menu
watermarkbooleantrueThe corner mark; mount-time only
storeStoreExternal store for controlled usage
snapshotJSONDocument loaded on mount (ignored when store is given)
camera{ x, y, z }Initial camera
styles{ color, size, dash, fill, font }Initial pen styles
autoFitbooleanfalseFit content on mount and container resize
className, styleApplied to the host div

Callbacks

PropFires
onMount(editor, ui)Once, after the board is ready
onChange(diff, source, editor)Every document change — see the data model
onSelectionChange(ids, editor)Selection changed
onThemeChange(themeId, editor)The in-board switch moved the theme
onGridChange(gridId, editor)The in-board switch moved the grid
onSave(blob, background)Toolbar PNG export — intercept it

onThemeChange / onGridChange exist so the board menu’s switches can flow back into your app state:

const [theme, setTheme] = useState('light') <Quickdraw theme={theme} onThemeChange={setTheme} />

The ref

The ref exposes the whole engine — every imperative API in these docs is reachable from it:

const ref = useRef(null) <Quickdraw ref={ref} /> ref.current.editor.setTool('draw') ref.current.editor.fitContent({ animate: 220 }) ref.current.editor.store.undo() ref.current.ui.setHidden(true)

Controlled usage

Pass your own Store when the document outlives the component — shared between views, preloaded before render, or synced with peers:

import { Quickdraw, useQuickdrawStore } from '@quickdrawjs/react' function App({ savedSnapshot }) { const store = useQuickdrawStore(savedSnapshot) // stable across renders return <Quickdraw store={store} /> }

Two components rendering the same store show the same live document — that’s the quickest way to see the sync model working.

Last updated on