Skip to content

RAF service

The RAF (short for requestAnimationFrame) service will help you manage your render loops.

Usage

js
import { useRaf } from '@studiometa/js-toolkit';

const { add, remove, props } = useRaf();

add('custom-id', (props) => {
  console.log(props.time); // latest `performance.now()`

  // Read the DOM and compute values...

  return () => {
    // Update the DOM...
  };
});

// Get the latest prop object
console.log(props());

// Remove the callback
remove('custom-id');

Props

time

  • Type: Number

The time elapsed since the time origin.

TIP

Read the performance.now() documentation to find out more on the time origin.

MIT Licensed