Skip to content

useTimeout

Category
Export Size
402 B
Last Changed
6 months ago

Update value after a given time with controls.

Demo

Ready: true

Usage

ts
import { 
useTimeout
} from '@vueuse/core'
const
ready
=
useTimeout
(1000)
ts
const { 
ready
,
start
,
stop
} =
useTimeout
(1000, {
controls
: true })
ts
import { 
promiseTimeout
} from '@vueuse/core'
console
.
log
(ready.value) // false
await
promiseTimeout
(1200)
console
.
log
(ready.value) // true

Type Declarations

ts
export interface 
UseTimeoutOptions
<
Controls
extends boolean>
extends UseTimeoutFnOptions { /** * Expose more controls * * @default false */
controls
?:
Controls
/** * Callback on timeout */
callback
?:
Fn
} export type
UseTimoutReturn
=
|
ComputedRef
<boolean>
| ({ readonly
ready
:
ComputedRef
<boolean>
} &
Stoppable
)
/** * Update value after a given time with controls. * * @see {@link https://vueuse.org/useTimeout} * @param interval * @param options */ export declare function
useTimeout
(
interval
?:
MaybeRefOrGetter
<number>,
options
?:
UseTimeoutOptions
<false>,
):
ComputedRef
<boolean>
export declare function
useTimeout
(
interval
:
MaybeRefOrGetter
<number>,
options
:
UseTimeoutOptions
<true>,
): {
ready
:
ComputedRef
<boolean>
} &
Stoppable

Source

SourceDemoDocs

Contributors

Anthony Fu
Anthony Fu
NoiseFan
SerKo
Robin
IlyaL
OrbisK
huiliangShen
Waleed Khaled
vaakian X
Jelf
Shinigami
Mark Noonan

Changelog

v13.1.0 on
c1d6e - feat(shared): ensure return types exists (#4659)
v12.8.0 on
7432f - feat(types): deprecate MaybeRef and MaybeRefOrGetter in favor of Vue's native (#4636)
v12.0.0-beta.1 on
0a9ed - feat!: drop Vue 2 support, optimize bundles and clean up (#4349)
v10.10.0 on
4eede - feat: target support reactivity (#3923)

Released under the MIT License.

Turn AI into a coding partner
Claim 40% off for AIDD Masterclass.
Get discount