Skip to content

Instantly share code, notes, and snippets.

@alxrocha
Forked from mattgperry/useAnimationLoop.js
Created August 7, 2019 20:51
Show Gist options
  • Save alxrocha/f5525370bc846fad0aa8029f03a9cfe3 to your computer and use it in GitHub Desktop.
Save alxrocha/f5525370bc846fad0aa8029f03a9cfe3 to your computer and use it in GitHub Desktop.
Use Framesync via a render loop
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