Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Apply VueUse composables in Vue 3/Nuxt projects to replace custom implementations with battle-tested utilities.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/useArrayMap.md
1---2category: Array3---45# useArrayMap67Reactive `Array.map`89## Usage1011### Use with array of multiple refs1213```ts14import { useArrayMap } from '@vueuse/core'1516const item1 = ref(0)17const item2 = ref(2)18const item3 = ref(4)19const item4 = ref(6)20const item5 = ref(8)21const list = [item1, item2, item3, item4, item5]22const result = useArrayMap(list, i => i * 2)23// result.value: [0, 4, 8, 12, 16]24item1.value = 125// result.value: [2, 4, 8, 12, 16]26```2728### Use with reactive array2930```ts31import { useArrayMap } from '@vueuse/core'3233const list = ref([0, 1, 2, 3, 4])34const result = useArrayMap(list, i => i * 2)35// result.value: [0, 2, 4, 6, 8]36list.value.pop()37// result.value: [0, 2, 4, 6]38```3940## Type Declarations4142```ts43export type UseArrayMapReturn<T = any> = ComputedRef<T[]>44/**45* Reactive `Array.map`46*47* @see https://vueuse.org/useArrayMap48* @param list - the array was called upon.49* @param fn - a function that is called for every element of the given `list`. Each time `fn` executes, the returned value is added to the new array.50*51* @returns a new array with each element being the result of the callback function.52*53* @__NO_SIDE_EFFECTS__54*/55export declare function useArrayMap<T, U = T>(56list: MaybeRefOrGetter<MaybeRefOrGetter<T>[]>,57fn: (element: T, index: number, array: T[]) => U,58): UseArrayMapReturn<U>59```60