Skip to content

⬅️ Back to Table of Contents

📄 useArrayFind

📊 Analysis Summary

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

📚 Table of Contents

🛠️ File Location:

📂 packages/shared/useArrayFind/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

useArrayFind(list: MaybeRefOrGetter<MaybeRefOrGetter<T>[]>, fn: (element: T, index: number, array: Mayb…): UseArrayFindReturn<T>

Reactive Array.find

Parameters:

  • list any: the array was called upon.
  • fn any: a function to test each element.

Returns: undefined the first element in the array that satisfies the provided testing function. Otherwise, undefined is returned.

See: https://vueuse.org/useArrayFind

Tags: @__NO_SIDE_EFFECTS__

Raw JSDoc
/**
 * Reactive `Array.find`
 *
 * @see https://vueuse.org/useArrayFind
 * @param list - the array was called upon.
 * @param fn - a function to test each element.
 *
 * @returns the first element in the array that satisfies the provided testing function. Otherwise, undefined is returned.
 *
 * @__NO_SIDE_EFFECTS__
 */

Calls:

  • computed (from vue)
  • toValue (from vue)
  • toValue(list) .find
  • fn
Code
export function useArrayFind<T>(
  list: MaybeRefOrGetter<MaybeRefOrGetter<T>[]>,
  fn: (element: T, index: number, array: MaybeRefOrGetter<T>[]) => boolean,
): UseArrayFindReturn<T> {
  return computed(() =>
    toValue<T | undefined>(
      toValue(list)
        .find((element, index, array) => fn(toValue(element), index, array)),
    ))
}

Type Aliases

UseArrayFindReturn<T = any>

type UseArrayFindReturn<T = any> = ComputedRef<T | undefined>;

Generated by Syntax Scribe