useRafFn

Call the function on every request animation frame with the ability to pause and play

Demo

Frames: 0

Delta: 0ms

FPS: 60

isPaused: false

Usage

const [count, setCount] = useState(0)
const [delta, setDelta] = useState(0)
const controls = useRafFn(
  ({ delta }) => {
    setCount(($count) => $count + 1)
    setDelta(delta)
  },
  {
    fpsLimit: 60,
    immediate: true,
  }
)

Type declaration

import { 
const useRafFn: (callback: (arg: RefFnArg) => void, options?: RefFnOptions) => {
    isActive: boolean;
    start: () => void;
    stop: () => void;
}
useRafFn
} from "@kaioken-core/hooks"
const
const controls: {
    isActive: boolean;
    start: () => void;
    stop: () => void;
}
controls
=
function useRafFn(callback: (arg: RefFnArg) => void, options?: RefFnOptions): {
    isActive: boolean;
    start: () => void;
    stop: () => void;
}
useRafFn
((options: RefFnArgoptions) => {}, {
fpsLimit?: number | undefinedfpsLimit: var undefinedundefined, immediate?: boolean | undefinedimmediate: false, })