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

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