How can I reuse an existing canvas element from multiple components? #2059
-
I'd like to have a center canvas element and draw to it from multiple sources. While I could put everything inside one My current solution is to split those components into two parts, one being in the "canvas" tree and the other in the regular DOM tree, but that's quite inconvenient when it comes to communication between them. What I'd like would be something like: const canvas = useRef();
<>
<Canvas ref={canvas}/>
<A canvas={canvas}/>
<B canvas={canvas}/>
</> And then in the components: function A({canvas}) {
return (<>
<ReuseCanvas canvas={canvas}>
<mesh ... />
</ReuseCanvas>
<div>
DOM goes here
</div>
);
} So far my research has brought me to export function ReuseView3D(props: ReuseViewProps) {
useLayoutEffect(() => {
render(
props.children,
props.canvasRef.current
)
}, [props.children, props.canvasRef.current])
return null;
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I'd suggest something like https://github.com/pmndrs/tunnel-rat for this. |
Beta Was this translation helpful? Give feedback.
I'd suggest something like https://github.com/pmndrs/tunnel-rat for this.