Skip to content

useLastChanged

Category
Export Size
188 B
Last Changed
7 months ago

Records the timestamp of the last change

Demo

Last changed: 5 minutes ago (1763176146957)

Usage

ts
import { 
useLastChanged
} from '@vueuse/core'
import {
nextTick
} from 'vue'
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

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

Source

SourceDemoDocs

Contributors

Anthony Fu
Robin
IlyaL
James Garbutt
yaoyin
Jady Dragon
Alex Kozack

Changelog

v13.1.0 on
c1d6e - feat(shared): ensure return types exists (#4659)
v12.0.0-beta.1 on
0a9ed - feat!: drop Vue 2 support, optimize bundles and clean up (#4349)

Released under the MIT License.

Black Friday Early Bird
Get 60% off + 7 premium Vue mastery bonuses
4 Workshops + 2 AI Courses + Certification
Buy Now
TIME LMITED OFFER