11

i have been trying to add a scroll area to my the app i was building but i just keep getting this error:

Uncaught Div is not part of the THREE namespace! Did you forget to extend?

I'm very new to three.js and it is even more compicated because i use React.

Here is the code for the App Component(where the error seems to originate from:

import './App.css';
import Header from "./Header";
import WebFont from "webfontloader";
import { useEffect, useRef } from "react";
import { Canvas } from "@react-three/fiber";
import Intro from "./Intro";
import { Stars } from "@react-three/drei";
import About from "./About";
import state from "./state";

function App() {
  useEffect(() => {
    WebFont.load({
      google: {
        families: ["Cookie", "Lora", "Playfair Display", "Inknut Antiqua", "Cormorant", "Share Tech Mono"]
      }
    });
  }, []);

  const domContent = useRef();
  const scrollArea = useRef();
  const onScroll = (e) => (state.top.current = e.target.scrollTop);
  useEffect(() => void onScroll({ target: scrollArea.current }), []);

  return (
    <div className="App">
      <Header />
      <Canvas camera={{ position: [0, 0, 120], fov: 70 }}>
        <Stars radius={300} depth={60} factor={7} fade={true} />
        <pointLight color="white" position={[5, 2, 5]} intensity={1.3} />
        <Intro domContent={domContent} />
        <About domContent={domContent} />
      </Canvas>
      <div className="scrollArea" ref={scrollArea} onScroll={onScroll}>
        <div style={{ position: "sticky", top: 0 }} ref={domContent}></div>
        <div style={{ height: `${state.pages * 100}vh` }}></div>
      </div>
    </div>
  );
}

export default App;
WestLangley
  • 102,557
  • 10
  • 276
  • 276
Jeoffrey Duke
  • 143
  • 1
  • 11

3 Answers3

4

When you are using HTML inside the canvas, just wrap your HTML with Html helper from @react-three/drei.

import { Html } from "@react-three/drei"
...
...
...
<Html>
   <div className={'title'}>
     <span className={'slogan'}>Slogan</span>
   </div>
</Html>
BB.
  • 169
  • 1
  • 12
0

Because your div inside the Canvas element.

return (
  <div>
    Something should be here
  <\div>
  <Canvas>
    ...
    ...
    ...
  <\Canvas>
)
BB.
  • 169
  • 1
  • 12
0

I got this same error and resolved the issue just by wrapping my canvas inside a react fragment.

Using 3rd-party objects declaratively

The extend function extends React Three Fiber's catalogue of JSX elements. Components added this way can then be referenced in the scene-graph using camel casing similar to other primitives.

<>
  <Canvas camera={{ position: [0, 0, 120], fov: 70 }}>
    { TODO }
  </Canvas>
</>
Qwerty
  • 578
  • 1
  • 5
  • 31