Skip to content

Timers

useMicrotask

The same as queueMicrotask, but with lifecycle support.

  • If the current lifecycle is disposed, the callback is never called.
  • The lifecycle within the callback is treated as the current lifecycle.
import { useMicrotask } from "rvx/async";

useMicrotask(() => { ... });
import { useMicrotask } from "./rvx.async.js";

useMicrotask(() => { ... });

useTimeout

The same as useTimeout, but with lifecycle support.

  • If the current lifecycle is disposed, the timeout is cleared.
  • The lifecycle within the callback is treated as the current lifecycle.
import { useTimeout } from "rvx/async";

useTimeout(() => { ... }, 1000);
import { useTimeout } from "./rvx.async.js";

useTimeout(() => { ... }, 1000);

useInterval

The same as setInterval, but with lifecycle support.

  • If the current lifecycle is disposed, the interval is cleared.
  • The lifecycle within the callback is disposed when the interval is cleared and before each call.
import { useInterval } from "rvx/async";

useInterval(() => { ... }, 1000);
import { useInterval } from "./rvx.async.js";

useInterval(() => { ... }, 1000);

useAnimation

Repeatedly request animation frames using requestAnimationFrame.

  • If the current lifecycle is disposed, the latest request is cancelled.
  • The lifecycle within the callback is disposed before each call and when the current lifecycle is disposed.
import { useAnimation } from "rvx/async";

useAnimation(() => { ... });