UNPKG

animare

Version:

Advanced animation library for modern JavaScript.

14 lines 662 B
import{useEffect}from'react';import animare from'animare';/** * A game loop that executes a callback function on each animation frame. * * @param onUpdateCallback - The callback function to be executed on each animation frame. It receives the delta time since the last frame as a parameter. * * @example * import { useLoop } from 'animare/react'; * * useLoop(delta => { * // do something * }, []); * */export function useLoop(onUpdateCallback){let deps=arguments.length>1&&arguments[1]!==undefined?arguments[1]:[];useEffect(()=>{const stop=animare.loop(onUpdateCallback);return stop;// eslint-disable-next-line react-hooks/exhaustive-deps },deps);}