diff --git a/packages/playground/src/r3f/App.tsx b/packages/playground/src/r3f/App.tsx
index bdb19b6..05eb7d1 100644
--- a/packages/playground/src/r3f/App.tsx
+++ b/packages/playground/src/r3f/App.tsx
@@ -1,4 +1,4 @@
-import {editable as e, bindToCanvas} from '@theatre/plugin-r3f'
+import {editable as e, Wrapper} from '@theatre/plugin-r3f'
import {PerspectiveCamera} from '@react-three/drei'
import {getProject} from '@theatre/core'
import * as THREE from 'three'
@@ -97,56 +97,57 @@ function App() {
)
diff --git a/packages/playground/src/space-exploration/App.tsx b/packages/playground/src/space-exploration/App.tsx
index 75be028..95bc977 100644
--- a/packages/playground/src/space-exploration/App.tsx
+++ b/packages/playground/src/space-exploration/App.tsx
@@ -1,5 +1,5 @@
-import {editable as e, bindToCanvas} from '@theatre/plugin-r3f'
-import {Stars} from '@react-three/drei'
+import {editable as e, Wrapper} from '@theatre/plugin-r3f'
+import {OrbitControls, Stars} from '@react-three/drei'
import {getProject} from '@theatre/core'
import React, {Suspense} from 'react'
import {Canvas} from '@react-three/fiber'
@@ -49,50 +49,47 @@ function App() {
const bg = '#272730'
return (
-
)
diff --git a/packages/plugin-r3f/src/index.tsx b/packages/plugin-r3f/src/index.tsx
index 1f0e3f0..f2e5210 100644
--- a/packages/plugin-r3f/src/index.tsx
+++ b/packages/plugin-r3f/src/index.tsx
@@ -4,11 +4,32 @@ export {default as EditorHelper} from './components/EditorHelper'
export type {EditorHelperProps} from './components/EditorHelper'
export {default as editable} from './components/editable'
-export {bindToCanvas} from './store'
export type {EditableState, BindFunction} from './store'
import studio from '@theatre/studio'
import Toolbar from './components/Toolbar/Toolbar'
import {types} from '@theatre/core'
+import React, {useLayoutEffect} from 'react'
+import {useThree} from '@react-three/fiber'
+import type {ISheet} from '@theatre/core'
+import {bindToCanvas} from './store'
+
+export const Wrapper: React.FC<{
+ getSheet: () => ISheet
+}> = (props) => {
+ const {scene, gl} = useThree((s) => ({scene: s.scene, gl: s.gl}))
+
+ useLayoutEffect(() => {
+ const sheet = props.getSheet()
+ if (!sheet || sheet.type !== 'Theatre_Sheet_PublicAPI') {
+ throw new Error(
+ `getSheet() in has returned an invalid value`,
+ )
+ }
+ bindToCanvas({sheet})({gl, scene})
+ }, [scene, gl])
+
+ return <>{props.children}>
+}
if (process.env.NODE_ENV === 'development') {
studio.extend({