A viewer on your own canvas
Mount the viewport on a canvas of yours (asynchronously: WebGPU, else WebGL2), unmount it when done.
import {
Viewer,
} from '@stereograph/teiaviewer';
import { useEffect, useRef } from 'react';
const viewer = new Viewer({
dev: {
debug: true,
},
});
/**
* App component setting up a viewer and a viewport
* @returns
*/
export const App = () => {
const canvasRef = useRef<HTMLCanvasElement | null>(null);
useEffect(() => {
if (!canvasRef.current) {
return;
}
// Drawn once the engine has its backend (WebGPU, else WebGL2).
void viewer.viewport.mount(canvasRef.current);
return () => {
viewer.viewport.unmount();
};
}, []);
return (
<div style={{
width: '100vw',
height: '100vh',
}}
>
<canvas
ref={canvasRef}
style={{
width: '100vw',
height: '100vh',
}}
/>
</div>
);
};