Can't use non-three.js elements like <div> inside a <Canvas>?
See original GitHub issueAgain 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
const target = catalogue[name] || THREE[name]
instance = Array.isArray(args) ? new target(...args) : new target(args)
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
The above error occurred in the <ul> component:
in ul (created by SelectableMenu)
But the error itself seems to be logged after that statement:
Uncaught TypeError: target is not a constructor
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?
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
Can't use non-three.js elements like <div> inside a <Canvas>?
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...
Read more >Unable to use <canvas> element inside <div> element
I'm not able to add <canvas> animation inside <div> element. With the current code, animation takes full page and I want to encapsulate ......
Read more >HTML Canvas Tutorial - W3Schools
The HTML <canvas> element is used to draw graphics, on the fly, via scripting (usually JavaScript). The <canvas> element is only a container...
Read more >Getting Started with the Canvas - KIRUPA
Get your feet wet using the canvas element by looking at a simple example and the HTML, CSS, and JavaScript that goes with...
Read more >HTML <canvas> Accessibility - Paul J. Adam
Canvas element must have an accessible name and description that matches the visible text and content inside the canvas drawing area. Canvas elements...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

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.
yes, you can exchange the renderer: https://github.com/drcmda/react-three-fiber/blob/master/readme.md#switching-the-default-renderer