Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Apply VueUse composables in Vue 3/Nuxt projects to replace custom implementations with battle-tested utilities.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/useRafFn.md
1---2category: Animation3---45# useRafFn67Call function on every `requestAnimationFrame`. With controls of pausing and resuming.89## Usage1011```ts12import { useRafFn } from '@vueuse/core'13import { shallowRef } from 'vue'1415const count = shallowRef(0)1617const { pause, resume } = useRafFn(() => {18count.value++19console.log(count.value)20})21```2223## Type Declarations2425```ts26export interface UseRafFnCallbackArguments {27/**28* Time elapsed between this and the last frame.29*/30delta: number31/**32* Time elapsed since the creation of the web page. See {@link https://developer.mozilla.org/en-US/docs/Web/API/DOMHighResTimeStamp#the_time_origin Time origin}.33*/34timestamp: DOMHighResTimeStamp35}36export interface UseRafFnOptions extends ConfigurableWindow {37/**38* Start the requestAnimationFrame loop immediately on creation39*40* @default true41*/42immediate?: boolean43/**44* The maximum frame per second to execute the function.45* Set to `null` to disable the limit.46*47* @default null48*/49fpsLimit?: MaybeRefOrGetter<number | null>50/**51* After the requestAnimationFrame loop executed once, it will be automatically stopped.52*53* @default false54*/55once?: boolean56}57/**58* Call function on every `requestAnimationFrame`. With controls of pausing and resuming.59*60* @see https://vueuse.org/useRafFn61* @param fn62* @param options63*/64export declare function useRafFn(65fn: (args: UseRafFnCallbackArguments) => void,66options?: UseRafFnOptions,67): Pausable68```69