-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't use non-three.js elements like <div> inside a <Canvas>? #47
Comments
See #34 A reconciler renders JSX into a target. react-dom renders into the dom, react-three-fiber renders into a threejs scene. You can't mount a div into a scene. |
Makes sense. I was able to do it with react-three-renderer but I don't think that uses a customer reconciler internally. |
May it be possible to use useThree() hook outside of Canvas elements? A solution may be adding something like domChildren prop to , to have them excluded by the renderer but still be able to access useThree(). |
useThree is context based, it only works inside canvas. But it goes deeper, generally the real three canvas isn't created in line with the Canvas component. Just because Canvas has rendered and the parent gets its useEffect ping doesn't mean that the three js stuff is ready yet. React decides when it will render, and it seems to do it async by default. So the only safe way is to pass the camera up when it becomes available. But you still have multiple options here.
function Parent() {
return <Child onCreated={({ camera }) => console.log(camera)} />
}
function Child(props) {
return <Canvas {...props} />
}
<Canvas>
{({ camera }) => ... }
|
Can CSS2DRenderer in THREE fits in this situation? |
yes, you can exchange the renderer: https://github.com/drcmda/react-three-fiber/blob/master/readme.md#switching-the-default-renderer |
Again i'm a reconciler newcomer, but these lines look suspect in the
createInstance
method:https://github.com/drcmda/react-three-fiber/blob/master/src/reconciler.js#L129-L130
Two things seem to happen. First, the error itself seems to be getting eaten somewhere, but I'm not sure where. All that's logged is
But the error itself seems to be logged after that statement:
This error itself isn't this most obvious to debug.
Why would I want to put a
<div>
inside a<Canvas>
you ask? I'm using react-portal to make my 3d menu element also be able to render a DOM element, and have both the 3d element and GUI element use the same props. It's pretty convenient.That doesn't seem compatible with this library. Do you have a suggestion for another approach?
The text was updated successfully, but these errors were encountered: