From 36846233046137d5f3f6eab6848812fcc7cbcfb3 Mon Sep 17 00:00:00 2001 From: "Brian D. Baker" Date: Thu, 9 Jan 2025 18:28:40 -0600 Subject: [PATCH] Simplify map-reduce to some and every in useLoadData --- hooks/useLoadData/useLoadData.ts | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/hooks/useLoadData/useLoadData.ts b/hooks/useLoadData/useLoadData.ts index b6c6e85..10139c5 100644 --- a/hooks/useLoadData/useLoadData.ts +++ b/hooks/useLoadData/useLoadData.ts @@ -68,14 +68,12 @@ function correctOptionalDependencies(args?: readonly [...Dep } function checkArgsAreLoaded(args?: readonly [...Deps]) { - return (args || []) - .map((arg: unknown) => { - if (isApiResponseBase(arg)) { - return !(arg.isInProgress || arg.isError); - } - return true; - }) - .reduce((prev, curr) => prev && curr, true); + return (args || []).every((arg: unknown) => { + if (isApiResponseBase(arg)) { + return !(arg.isInProgress || arg.isError); + } + return true; + }); } function normalizeArgumentOverloads( @@ -283,14 +281,12 @@ export function useLoadData( const correctedArgs = correctOptionalDependencies(fetchDataArgs); const argsAreLoaded = checkArgsAreLoaded(correctedArgs); - const argsHaveErrors = (correctedArgs || []) - .map((arg: unknown) => { - if (isApiResponseBase(arg)) { - return arg.isError; - } - return false; - }) - .reduce((prev, curr) => prev || curr, false); + const argsHaveErrors = (correctedArgs || []).some((arg: unknown) => { + if (isApiResponseBase(arg)) { + return arg.isError; + } + return false; + }); if (argsHaveErrors) { setPendingData({