useRaf
Use requestAnimationFrame to invoke the callback before the browser repainting.
API
function useRaf(callback: () => void): [start: () => void, cancel: () => void];
Params:
callback
: A function that will be invoked.
Results:
start
: Start function.cancel
: Cancel function.
Example
import React from "react";
import { useRaf } from "@lilib/hooks";
function Example() {
const [start, cancel] = useRaf(() => {
// Do something
});
}