tldraw/www/components/editor.tsx
Steve Ruiz be2c6d6d1f
[refactor] events (#230)
* bumps rko, adds events

* rename tlstate to state, fix env for multiplayer test

* Fix multiplayer

* rename data tldrawstate to tldrawsnapshot

* Update multiplayer-editor.tsx

* Fix shhhmp

* Update 2.tldr

* Add API to the README
2021-11-08 14:21:37 +00:00

40 lines
978 B
TypeScript

import { TLDraw, TLDrawState, useFileSystem } from '@tldraw/tldraw'
import * as gtag from '-utils/gtag'
import React from 'react'
interface EditorProps {
id?: string
}
export default function Editor({ id = 'home' }: EditorProps) {
// Put the state into the window, for debugging.
const handleMount = React.useCallback((state: TLDrawState) => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
window.state = state
}, [])
// Send events to gtag as actions.
const handlePersist = React.useCallback((_state: TLDrawState, reason?: string) => {
gtag.event({
action: reason,
category: 'editor',
label: reason || 'persist',
value: 0,
})
}, [])
const fileSystemEvents = useFileSystem()
return (
<div className="tldraw">
<TLDraw
id={id}
onMount={handleMount}
onPersist={handlePersist}
autofocus
{...fileSystemEvents}
/>
</div>
)
}