Allow setting user as a prop (#1832)

Add `user` as a prop to `TldrawEditor`

### Change Type

- [x] `patch` — Bug fix
This commit is contained in:
alex 2023-08-30 14:26:14 +01:00 committed by GitHub
parent e3b07631ce
commit 3bde22a482
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 1 deletions

View file

@ -1997,6 +1997,7 @@ export interface TldrawEditorBaseProps {
onMount?: TLOnMountHandler; onMount?: TLOnMountHandler;
shapeUtils?: readonly TLAnyShapeUtilConstructor[]; shapeUtils?: readonly TLAnyShapeUtilConstructor[];
tools?: readonly TLStateNodeConstructor[]; tools?: readonly TLStateNodeConstructor[];
user?: TLUser;
} }
// @public // @public

View file

@ -98,6 +98,11 @@ export interface TldrawEditorBaseProps {
* A classname to pass to the editor's container. * A classname to pass to the editor's container.
*/ */
className?: string className?: string
/**
* The user interacting with the editor.
*/
user?: TLUser
} }
/** /**
@ -126,10 +131,11 @@ export const TldrawEditor = memo(function TldrawEditor({
store, store,
components, components,
className, className,
user: _user,
...rest ...rest
}: TldrawEditorProps) { }: TldrawEditorProps) {
const [container, rContainer] = React.useState<HTMLDivElement | null>(null) const [container, rContainer] = React.useState<HTMLDivElement | null>(null)
const user = useMemo(() => createTLUser(), []) const user = useMemo(() => _user ?? createTLUser(), [_user])
const ErrorFallback = const ErrorFallback =
components?.ErrorFallback === undefined ? DefaultErrorFallback : components?.ErrorFallback components?.ErrorFallback === undefined ? DefaultErrorFallback : components?.ErrorFallback