UNPKG

rvx

Version:

A signal based rendering library

75 lines (52 loc) 1.67 kB
# 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. === "JSX" ```jsx import { useMicrotask } from "rvx/async"; useMicrotask(() => { ... }); ``` === "No Build" ```jsx 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. === "JSX" ```jsx import { useTimeout } from "rvx/async"; useTimeout(() => { ... }, 1000); ``` === "No Build" ```jsx 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. === "JSX" ```jsx import { useInterval } from "rvx/async"; useInterval(() => { ... }, 1000); ``` === "No Build" ```jsx 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. === "JSX" ```jsx import { useAnimation } from "rvx/async"; useAnimation(() => { ... }); ```