Skip to content

Instantly share code, notes, and snippets.

@mattgperry
Last active August 8, 2019 17:14
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mattgperry/9e5b8d51a6da8e3d443737232593fcc3 to your computer and use it in GitHub Desktop.
Save mattgperry/9e5b8d51a6da8e3d443737232593fcc3 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