Skip to content

useLastChanged

Category
Export Size
143 B
Last Changed
last year

Records the timestamp of the last change

Demo

Last changed: 5 minutes ago (1738418320551)

Usage

ts
import { useLastChanged } from '@vueuse/core'
import { nextTick } from 'vue-demi'

const a = ref(0)
const lastChanged = useLastChanged(a)

a.value = 1

await nextTick()

console.log(lastChanged.value) // 1704709379457

By default the change is recorded on the next tick (watch() with flush: 'post'). If you want to record the change immediately, pass flush: 'sync' as the second argument.

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

const a = ref(0)
const lastChanged = useLastChanged(a, { flush: 'sync' })

a.value = 1

console.log(lastChanged.value) // 1704709379457

Type Declarations

typescript
export interface UseLastChangedOptions<
  Immediate extends boolean,
  InitialValue extends number | null | undefined = undefined,
> extends WatchOptions<Immediate> {
  initialValue?: InitialValue
}
/**
 * Records the timestamp of the last change
 *
 * @see https://vueuse.org/useLastChanged
 */
export declare function useLastChanged(
  source: WatchSource,
  options?: UseLastChangedOptions<false>,
): Ref<number | null>
export declare function useLastChanged(
  source: WatchSource,
  options: UseLastChangedOptions<true> | UseLastChangedOptions<boolean, number>,
): Ref<number>

Source

SourceDemoDocs

Contributors

Anthony Fu
yaoyin
Jady Dragon
Alex Kozack

Changelog

No recent changes

Released under the MIT License.

Conference Offer
Get 50% OFF a Vue School Yearly or Lifetime Plan
Access 1400+ lessons on Vue, Pinia, Vite, Tailwind + more
Get Offer
09
hours
:
06
minutes
:
19
seconds
: