Vev Help Center
Search…
useFrame hook
Triggers a callback function every animation frame. Optionally pass a time parameter in your callback function to track callback start time. useFrame() calls are paused when running in background tabs.
In the past, setTimeout and setInterval were commonly used to iterate a block of code for animations. Using these causes the browser to paint frames quicker than most screen refresh rates of 60 FPS. This results in skipped frames and unnecessary computation, making snappy animations. UseFrame() executes the passed call back function more efficiently by eliminating unnecessary repaints and bundling multiple animations into a single repaint cycle.

Usage

1
useFrame(callback: (time?: number), deps?: readonly any[]): () => void;
Copied!

Example

Sliding an element to the right by 500px.
1
import { useFrame } from 'vev';
2
​
3
export default function() {
4
var startTime = null;
5
​
6
useFrame((time) => {
7
if(!startTime) startTime = time;
8
var progress = time - startTime;
9
const boxElement = document.getElementById('SomeElementYouWantToAnimate');
10
if(progress < 5000){
11
boxElement.style.left = (progress / 10) + 'px';
12
}
13
});
14
​
15
return (
16
<div className="fill">
17
<div id="SomeElementYouWantToAnimate" style={{left: 0}}></div>
18
</div>
19
);
20
}
Copied!
Copy link
Contents
Usage
Example