UNPKG

@ledgerhq/live-common

Version:
21 lines 872 B
/** * * @param hooks - An array of functions that take an array of items of type T and return an array of items of type U or undefined. * @template T - The type of the items in the input array. * @template U - The type of the items in the output array. * @description This function composes multiple hooks into a single hook that processes an array of items of type T and returns an array of items of type T & U. * @returns A function that takes an array of items of type T and returns an array of items of type T & U. * */ export function composeHooks(...hooks) { return (items) => { return hooks.reduce((acc, hook) => { const result = hook?.(acc) ?? []; return acc.map((item, i) => ({ ...item, ...result[i], })); }, items); }; } //# sourceMappingURL=composeHooks.js.map