Skip to content

useWatchArray

Category
Export Size
332 B
Last Changed
5 days ago

Watches an array value and reports which items were added and removed since the previous list

Demo

Usage

tsx
import { 
useWatchArray
} from '@reause/shared'
useWatchArray
(list, (
newList
,
oldList
,
added
,
removed
) => {
console
.
log
(`added: ${
added
}`, `removed: ${
removed
}`)
}) // fire once on mount with the current list
useWatchArray
(list, (
newList
,
oldList
,
added
,
removed
) => {
console
.
log
(
newList
,
oldList
,
added
,
removed
)
}, {
immediate
: true })

Type Declarations

ts
export interface UseWatchArrayCallback<V = any, OV = any> {
    (value: V, oldValue: OV, added: V, removed: OV): void;
}

export interface UseWatchArrayOptions<Immediate extends Readonly<boolean> = false> {
    immediate?: Immediate;
}

export function useWatchArray<T, Immediate extends Readonly<boolean> = false>(source: T[], cb: UseWatchArrayCallback<T[], Immediate extends true ? T[] | undefined : T[]>, options?: UseWatchArrayOptions<Immediate>): void

Source

Source · Demo · VueUse

Contributors

hairyf

Changelog

v0.1.0 on
b77b5 - fix(shared): resolve useWatchArray audit findings (#762)

Released under the MIT License. v0.1.8