@adyen/adyen-platform-experience-web
Version:

30 lines (29 loc) • 871 B
JavaScript
import { useState as f, useCallback as n, useEffect as u } from "../external/.pnpm/preact@10.28.2/node_modules/preact/hooks/dist/hooks.module.js";
import { isFunction as y } from "../utils/value/is.js";
const w = ({
records: s,
hasCustomColumn: r = !1,
onDataRetrieve: e,
mergeCustomData: a
}) => {
const [l, o] = f(s), [d, c] = f(!1), i = n(async () => {
try {
if (r && y(e)) {
const t = await e(s);
if (Array.isArray(t)) o(a({ records: s, retrievedData: t?.filter(Boolean) || [] }));
else throw new Error("Retrieved data should be an array");
} else
o(s);
} catch (t) {
o(s), console.error(t);
} finally {
c(!1);
}
}, [r, e, a, s]);
return u(() => {
r && e && c(!0), i();
}, [r, i, e]), { customRecords: l, loadingCustomRecords: d };
};
export {
w as useCustomColumnsData
};