Replies: 1 comment
-
You can use the import * as React from 'react'
import { createRoot, events } from '@react-three/fiber'
function CustomCanvas({ children }) {
// Init root from canvas
const [canvas, setCanvas] = React.useState()
const root = React.useMemo(() => canvas && createRoot(canvas, { events }), [canvas])
// Render children as a render-effect
root?.render(children)
// Cleanup on unmount
React.useEffect(() => () => root?.unmount(), [root])
// Use callback-style ref to access canvas in render
return <canvas ref={setCanvas} />
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I aim to integrate some of these tasty Components into another platform that also uses THREE.js.
That platform already initializes a canvas.
How might the Canvas component receive a querySelector and
use a found existing canvas in place of creating its own new one?
My perusal of Canvas.ts demonstrated lots of good Provider work needed for setup there.
Beta Was this translation helpful? Give feedback.
All reactions