Skip to content

⬅️ Back to Table of Contents

📄 useArrayMap

📊 Analysis Summary

Metric Count
🔧 Functions 1
📦 Imports 4
🟢 Vue Composition API 1
📑 Type Aliases 1

📚 Table of Contents

🛠️ File Location:

📂 packages/shared/useArrayMap/index.ts

📦 Imports

Name Source
ComputedRef vue
MaybeRefOrGetter vue
computed vue
toValue vue

Vue Composition API

Name Type Reactive Variables Composables
computed computed none none

Functions

useArrayMap(list: MaybeRefOrGetter<MaybeRefOrGetter<T>[]>, fn: (element: T, index: number, array: T[])…): UseArrayMapReturn<U>

Reactive Array.map

Parameters:

  • list any: the array was called upon.
  • fn any: 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.

Returns: undefined a new array with each element being the result of the callback function.

See: https://vueuse.org/useArrayMap

Tags: @__NO_SIDE_EFFECTS__

Raw JSDoc
/**
 * Reactive `Array.map`
 *
 * @see https://vueuse.org/useArrayMap
 * @param list - the array was called upon.
 * @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.
 *
 * @returns a new array with each element being the result of the callback function.
 *
 * @__NO_SIDE_EFFECTS__
 */

Calls:

  • computed (from vue)
  • toValue(list).map(i => toValue(i)).map
Code
export function useArrayMap<T, U = T>(
  list: MaybeRefOrGetter<MaybeRefOrGetter<T>[]>,
  fn: (element: T, index: number, array: T[]) => U,
): UseArrayMapReturn<U> {
  return computed(() => toValue(list).map(i => toValue(i)).map(fn))
}

Type Aliases

UseArrayMapReturn<T = any>

type UseArrayMapReturn<T = any> = ComputedRef<T[]>;

Generated by Syntax Scribe