Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions packages/playground/src/shared/dom/Scene.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { getStudioSync} from '@theatre/core'
import {getStudio, getStudioSync} from '@theatre/core'
import type {UseDragOpts} from './useDrag'
import useDrag from './useDrag'
import React, {useLayoutEffect, useMemo, useRef, useState} from 'react'
import React, {
useEffect,
useLayoutEffect,
useMemo,
useRef,
useState,
} from 'react'
import type {
IProject,
ISheet,
Expand Down Expand Up @@ -182,10 +188,14 @@ export const Scene: React.FC<{project: IProject}> = ({project}) => {
const sheet = project.sheet('Scene', 'default')
const [selection, setSelection] = useState<IStudio['selection']>()

useLayoutEffect(() => {
return getStudioSync()!.onSelectionChange((newState) => {
setSelection(newState)
useEffect(() => {
let unsubscribe = () => {}
getStudio().then((studio) => {
unsubscribe = studio.onSelectionChange((newState) => {
setSelection(newState)
})
})
return () => unsubscribe()
}, [])

const containerRef = useRef<HTMLDivElement>(null!)
Expand Down
1 change: 1 addition & 0 deletions packages/playground/src/shared/dom/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react'
import ReactDOM from 'react-dom/client'
import theatre from '@theatre/core'
import '@theatre/studio'
import {getProject} from '@theatre/core'
import {Scene} from './Scene'

Expand Down