Skip to content

Is there a way to combine react-three-fiber and regular three.js in a single app? #1626

Answered by drcmda
camjackson asked this question in Q&A
Discussion options

You must be logged in to vote

of course, r3f just sets up renderer+cam+scene for you, and you get to write jsx, but nothing would stop you doing this:

function Foo() {
  const [scene] = useState(() => new THREE.Scene())
  const state = useThree()
  useEffect(() => {
    // ... your plain three code here
    scene.add(your result)

    function resize() {
      // state.viewport and state.size have the correct sizes
    }

    window.addEventListener("onClick", () => ...
    
    function loop() {
      requestAnimationFrame(raf)
      scene.render(state.gl, camera)
    }
    loop()
  }, [])
  return <primitive object={scene} />
}

<Canvas frameloop="never">
  <Foo />

as you see you can already start using some helpers…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@camjackson
Comment options

@drcmda
Comment options

@camjackson
Comment options

Answer selected by camjackson
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants