Skip to content
On this page

autoResetRef

Category
Last Changed
3 months ago

A ref which will be reset to the default value after some time.

Demo

default message

Usage

import { autoResetRef } from '@vueuse/core'

const message = autoResetRef('default message', 1000)

const setMessage = () => {
  // here the value will change to 'message has set' but after 1000ms, it will change to 'default message'
  message.value = 'message has set'
}
import { autoResetRef } from '@vueuse/core'

const message = autoResetRef('default message', 1000)

const setMessage = () => {
  // here the value will change to 'message has set' but after 1000ms, it will change to 'default message'
  message.value = 'message has set'
}

Type Declarations

/**
 * Create a ref which will be reset to the default value after some time.
 *
 * @see https://vueuse.org/autoResetRef
 * @param defaultValue The value which will be set.
 * @param afterMs      A zero-or-greater delay in milliseconds.
 */
export declare function autoResetRef<T>(
  defaultValue: T,
  afterMs?: MaybeRef<number>
): Ref<T>
/**
 * Create a ref which will be reset to the default value after some time.
 *
 * @see https://vueuse.org/autoResetRef
 * @param defaultValue The value which will be set.
 * @param afterMs      A zero-or-greater delay in milliseconds.
 */
export declare function autoResetRef<T>(
  defaultValue: T,
  afterMs?: MaybeRef<number>
): Ref<T>

Source

SourceDemoDocs

Contributors

Anthony Fu
Alex Kozack
翠 / green

Changelog

v4.8.2 on 4/16/2021
88256 - feat: new function (#444)
autoResetRef has loaded