useRafFn
Call function on every requestAnimationFrame
. With controls of pausing and resuming.
Usage
<script>
import { writable } from '@svelte-use/shared'
import { useRafFn } from '@svelte-use/core'
const count = writable(0)
const { pause, resume } = useRafFn(() => {
$count++
console.log($count)
})
</script>
Type Declarations
export interface RafFnOptions extends ConfigurableWindow {
/**
* Start the requestAnimationFrame loop immediately on creation
*
* @default true
*/
immediate?: boolean
}
/**
* Call function on every `requestAnimationFrame`. With controls of pausing and resuming.
*
* @see https://svelte-use.vercel.app/core/useRafFn
* @param fn
* @param options
*/
export declare function useRafFn(fn: Fn, options?: RafFnOptions): Pausable