import { useEffect, useRef, useState } from "react"; import * as THREE from "three"; import Main from "@app/three/main"; export default function Three() { const mountRef = useRef(null); // Parent canva element const [loading, setLoading] = useState(true); // Loading boolean element useEffect(() => { if (!window.WebGL2RenderingContext) return; const loadingManager = new THREE.LoadingManager(() => setLoading(false)); new Main(mountRef.current!, loadingManager); }, []); // canva must exist before loading so that Main doesn't crash return (
{window.WebGL2RenderingContext ? <>
{loading && (
)} :
WebGL2 is not supported.
}
); };