Pulled ALL skills from 15 source repositories: - anthropics/skills: 16 (docs, design, MCP, testing) - obra/superpowers: 14 (TDD, debugging, agents, planning) - coreyhaines31/marketingskills: 25 (marketing, CRO, SEO, growth) - better-auth/skills: 5 (auth patterns) - vercel-labs/agent-skills: 5 (React, design, Vercel) - antfu/skills: 16 (Vue, Vite, Vitest, pnpm, Turborepo) - Plus 13 individual skills from various repos Mosaic Stack is not limited to coding — the Orchestrator and subagents serve coding, business, design, marketing, writing, logistics, analysis, and more. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
82 lines
1.9 KiB
Markdown
82 lines
1.9 KiB
Markdown
---
|
|
category: Array
|
|
---
|
|
|
|
# useArrayReduce
|
|
|
|
Reactive `Array.reduce`.
|
|
|
|
## Usage
|
|
|
|
```ts
|
|
import { useArrayReduce } from '@vueuse/core'
|
|
|
|
const sum = useArrayReduce([ref(1), ref(2), ref(3)], (sum, val) => sum + val)
|
|
// sum.value: 6
|
|
```
|
|
|
|
### Use with reactive array
|
|
|
|
```ts
|
|
import { useArrayReduce } from '@vueuse/core'
|
|
|
|
const list = reactive([1, 2])
|
|
const sum = useArrayReduce(list, (sum, val) => sum + val)
|
|
|
|
list.push(3)
|
|
// sum.value: 6
|
|
```
|
|
|
|
### Use with initialValue
|
|
|
|
```ts
|
|
import { useArrayReduce } from '@vueuse/core'
|
|
|
|
const list = reactive([{ num: 1 }, { num: 2 }])
|
|
const sum = useArrayReduce(list, (sum, val) => sum + val.num, 0)
|
|
// sum.value: 3
|
|
```
|
|
|
|
## Type Declarations
|
|
|
|
```ts
|
|
export type UseArrayReducer<PV, CV, R> = (
|
|
previousValue: PV,
|
|
currentValue: CV,
|
|
currentIndex: number,
|
|
) => R
|
|
export type UseArrayReduceReturn<T = any> = ComputedRef<T>
|
|
/**
|
|
* Reactive `Array.reduce`
|
|
*
|
|
* @see https://vueuse.org/useArrayReduce
|
|
* @param list - the array was called upon.
|
|
* @param reducer - a "reducer" function.
|
|
*
|
|
* @returns the value that results from running the "reducer" callback function to completion over the entire array.
|
|
*
|
|
* @__NO_SIDE_EFFECTS__
|
|
*/
|
|
export declare function useArrayReduce<T>(
|
|
list: MaybeRefOrGetter<MaybeRefOrGetter<T>[]>,
|
|
reducer: UseArrayReducer<T, T, T>,
|
|
): UseArrayReduceReturn<T>
|
|
/**
|
|
* Reactive `Array.reduce`
|
|
*
|
|
* @see https://vueuse.org/useArrayReduce
|
|
* @param list - the array was called upon.
|
|
* @param reducer - a "reducer" function.
|
|
* @param initialValue - a value to be initialized the first time when the callback is called.
|
|
*
|
|
* @returns the value that results from running the "reducer" callback function to completion over the entire array.
|
|
*
|
|
* @__NO_SIDE_EFFECTS__
|
|
*/
|
|
export declare function useArrayReduce<T, U>(
|
|
list: MaybeRefOrGetter<MaybeRefOrGetter<T>[]>,
|
|
reducer: UseArrayReducer<U, T, U>,
|
|
initialValue: MaybeRefOrGetter<U>,
|
|
): UseArrayReduceReturn<U>
|
|
```
|