Created
September 4, 2022 15:48
-
-
Save hmans/7579f86b22f426023c2b0dabf1a44cf0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useFrame } from "@react-three/fiber" | |
import { useRef } from "react" | |
/* TODO: Extract this into hmans/things or similar */ | |
export function useFrameEffect<T>( | |
dependencyCallback: () => T, | |
callback: (args: T) => void, | |
renderPriority = 0 | |
) { | |
const value = useRef<T>(null!) | |
useFrame(() => { | |
const newValue = dependencyCallback() | |
if (value.current !== newValue) { | |
value.current = newValue | |
callback(newValue) | |
} | |
}, renderPriority) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment