-
-
Save alxrocha/f5525370bc846fad0aa8029f03a9cfe3 to your computer and use it in GitHub Desktop.
Use Framesync via a render loop
This file contains 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 sync, { cancelSync } from "framesync"; | |
import { useEffect } from "react"; | |
/** | |
The code inside useAnimationLoop is guaranteed to run once a frame | |
before Framer Motion/Popmotion/Pose renders | |
useAnimationLoop(({ delta, timestamp }) => { | |
// do stuff | |
}) | |
**/ | |
export const useAnimationLoop = callback => { | |
useEffect(() => { | |
sync.update(callback, true); | |
return () => cancelSync.update(callback); | |
}, [callback]); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment