Skip to content
On this page

useTimeoutPoll

Category
Export Size
1.02 kB
Last Changed
7 months ago

Use timeout to poll something. It's will trigger callback after last task is done.

Demo

Count: 0
isActive: false

Usage

ts
import { useTimeoutPoll } from '@vueuse/core'

const count = ref(0)

const fetchData = async () => {
  await promiseTimeout(1000)
  count.value++
}

// Only trigger after last fetch is done
const { isActive, pause, resume } = useTimeoutPoll(fetchData, 1000)
import { useTimeoutPoll } from '@vueuse/core'

const count = ref(0)

const fetchData = async () => {
  await promiseTimeout(1000)
  count.value++
}

// Only trigger after last fetch is done
const { isActive, pause, resume } = useTimeoutPoll(fetchData, 1000)

Type Declarations

typescript
export declare function useTimeoutPoll(
  fn: () => Awaitable<void>,
  interval: MaybeComputedRef<number>,
  timeoutPollOptions?: UseTimeoutFnOptions
): Pausable
export declare function useTimeoutPoll(
  fn: () => Awaitable<void>,
  interval: MaybeComputedRef<number>,
  timeoutPollOptions?: UseTimeoutFnOptions
): Pausable

Source

SourceDemoDocs

Contributors

Anthony Fu
sun0day
Jelf
Wenlu Wang

Changelog

v9.0.0-beta.1 on 7/20/2022
4ca70 - fix(useTimeoutFn,useTimeout)!: rename type TimeoutOptions to UseTimeoutOptions and TimeoutFnOptions to UseTimeoutFnOptions (#1944)
v8.9.1 on 7/8/2022
a9ccc - feat(all): use MaybeComputedRef (#1768)
v8.0.0-beta.1 on 3/5/2022
abd59 - feat: new function (#1178)

Released under the MIT License.