React Hookers - v6.3.0
    Preparing search index...

    Function useAnimationFrame

    • Returns an API that starts and stops an animation loop.

      When start is called, the animation loop begins invoking the provided callback using requestAnimationFrame. If an animation is already running, it is stopped and restarted with the new callback.

      The animation is automatically stopped when the component unmounts.

      The animation should be started or stopped only after the component has mounted. Before that, calling either function is a no-op.

      Returns [start: (cb: FrameRequestCallback) => void, stop: () => void]

      const [start, stop] = useAnimationFrame();

      useEffect(() => {
      // Cancels any pending animation loop and schedules a new one
      start(() => {
      // Apply animation changes
      });

      // Stop the animation
      stop();
      }, []);