Best practice for accessing hooks outside of Canvas #1297
Unanswered
maxibenner
asked this question in
Q&A
Replies: 1 comment 1 reply
-
useFrame is context based, it won't work outside of canvas. there are multiple ways though. you could, or you could also use the subscribe api directly, it's part of the state model and just needs a react ref that points to the callback (useRef, createRef or fake it with { current: fn } function onFrame(state, delta) {
// will call this every frame
}
<Canvas onCreated={state => {
const sub = state.internal.subscribe({ current: frameRef }, priority)
// sub() to destroy it or global effects import { addEffect } from '@react-three/fiber'
const sub = addEffect(() => console.log("called every frame"))
// sub() to destroy it you also have complete clock control and you can advance the scene frame by frame using |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I am trying to build a hook for recording a scene based on useFrame(). What would be the best way to make useFrame available outside of the Canvas context? Would it be problematic to pass it up to a global state?
Beta Was this translation helpful? Give feedback.
All reactions