Last active
August 8, 2019 17:14
-
-
Save mattgperry/9e5b8d51a6da8e3d443737232593fcc3 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